xiaohongshu
xiaohongshu
memory-rag-instrumentation
Instrument RAG retrieval, memory operations, and context management
Full skill instructions
Instrument retrieval-augmented generation and memory operations for quality debugging.
RAG observability answers:
# Required (P0)
span.set_attribute("retrieval.source", "vector_store")
span.set_attribute("retrieval.query_length", 150)
span.set_attribute("retrieval.results_count", 5)
span.set_attribute("retrieval.latency_ms", 45)
# Quality signals (P1)
span.set_attribute("retrieval.top_score", 0.89)
span.set_attribute("retrieval.avg_score", 0.72)
span.set_attribute("retrieval.min_score", 0.55)
span.set_attribute("retrieval.above_threshold", 4) # Count above relevance threshold
# Context usage (P1)
span.set_attribute("retrieval.tokens_retrieved", 2500)
span.set_attribute("retrieval.tokens_used", 2000) # After truncation
span.set_attribute("retrieval.context_window_pct", 0.25) # % of context window
# Source tracking (P2)
span.set_attribute("retrieval.sources", ["doc1.pdf", "doc2.pdf"])
span.set_attribute("retrieval.collection", "knowledge_base")
with tracer.start_span("retrieval.query_process") as span:
span.set_attribute("query.original_length", len(query))
span.set_attribute("query.expanded", bool(expansion))
span.set_attribute("query.rewritten", bool(rewrite))
# Process query
with tracer.start_span("retrieval.vector_search") as span:
span.set_attribute("vector.index", "main_index")
span.set_attribute("vector.k", 10)
span.set_attribute("vector.ef_search", 100) # HNSW param
span.set_attribute("vector.distance_metric", "cosine")
# Execute search
with tracer.start_span("retrieval.rerank") as span:
span.set_attribute("rerank.model", "cohere-rerank-v3")
span.set_attribute("rerank.input_count", 10)
span.set_attribute("rerank.output_count", 5)
span.set_attribute("rerank.score_improvement", 0.15)
# Rerank results
with tracer.start_span("retrieval.context_assembly") as span:
span.set_attribute("context.chunks_selected", 5)
span.set_attribute("context.total_tokens", 2500)
span.set_attribute("context.max_tokens", 4000)
span.set_attribute("context.truncated", False)
# Assemble context
span.set_attribute("memory.type", "conversation")
span.set_attribute("memory.messages_stored", 10)
span.set_attribute("memory.tokens_stored", 3500)
span.set_attribute("memory.window_size", 20)
span.set_attribute("memory.pruned_count", 5)
span.set_attribute("memory.type", "persistent")
span.set_attribute("memory.operation", "write") # read, write, delete
span.set_attribute("memory.key", "user_preferences")
span.set_attribute("memory.store", "redis")
span.set_attribute("memory.ttl_seconds", 86400)
span.set_attribute("memory.type", "episodic")
span.set_attribute("memory.episode_id", "session_123")
span.set_attribute("memory.events_count", 15)
span.set_attribute("memory.summary_generated", True)
Track signals that indicate retrieval quality:
# Relevance scoring
span.set_attribute("quality.relevance_score", 0.85)
span.set_attribute("quality.coverage_score", 0.70) # How well query is covered
span.set_attribute("quality.diversity_score", 0.60) # Source diversity
# Failure signals
span.set_attribute("quality.no_results", False)
span.set_attribute("quality.below_threshold", 2) # Count below threshold
span.set_attribute("quality.fallback_used", False)
from langchain.retrievers import VectorStoreRetriever
from langfuse.decorators import observe
@observe(name="retrieval.search")
def search_documents(query: str, k: int = 5):
span = get_current_span()
results = retriever.get_relevant_documents(query)
span.set_attribute("retrieval.query_length", len(query))
span.set_attribute("retrieval.results_count", len(results))
span.set_attribute("retrieval.top_score", results[0].metadata.get("score", 0))
return results
from llama_index.core import VectorStoreIndex
from langfuse.decorators import observe
@observe(name="retrieval.query")
def query_index(query: str):
response = index.as_query_engine().query(query)
span = get_current_span()
span.set_attribute("retrieval.source_nodes", len(response.source_nodes))
return response
Track context usage to avoid truncation issues:
MODEL_CONTEXT_LIMITS = {
"claude-3-opus": 200_000,
"claude-3-5-sonnet": 200_000,
"gpt-4-turbo": 128_000,
"gpt-4o": 128_000,
}
def track_context_usage(model: str, tokens_used: int):
limit = MODEL_CONTEXT_LIMITS.get(model, 100_000)
pct = tokens_used / limit
span.set_attribute("context.tokens_used", tokens_used)
span.set_attribute("context.limit", limit)
span.set_attribute("context.utilization_pct", round(pct, 2))
span.set_attribute("context.near_limit", pct > 0.8)
llm-call-tracing - LLM instrumentationevaluation-quality - Quality metricsxiaohongshu
technical spec
product ux expert
database patterns
Conduct multi-agent task orchestration and workflow coordination.
Initialize project with Conductor artifacts (product definition,
Expert in web animations, transitions, and motion design using Framer Motion and CSS
Creates Mermaid and ASCII diagrams for flowcharts, architecture, ERDs, state machines, mindmaps, and more. Use when user mentions diagram, flowchart, mermaid, ASCII diagram, text diagram, terminal diagram, visualize, C4, mindmap, architecture diagram, sequence diagram, ERD, or needs visual docume...
PostgreSQL bindings for H3 hexagonal grid system. Use when working with H3 cells in Postgres, including spatial indexing, geometry/geography integration, and raster analysis.
Context-Driven Development skill for projects using Conductor. Use this skill when you detect a `conductor/` directory in the project, when working on tasks defined in a `plan.md` file, or when the user asks about tracks, specs, or plans. Automatically applies TDD workflow, tracks task completion...
Display project status, active tracks, and next actions
Official Stakpak application containerization standard operating procedure, a step-by-step guidline to properly dockerize applications. This is a rule book curated by the Stakpak Team.
Generate, edit, and beat-sync AI video with leading models in one workspace.
The world's fastest calendar for remote work
Transform Your Design with AI Designer by ImgCreator.ai
Revolutionizing Video Production with AI-Powered Creativity
Extend an image past the frame and let AI fill the new aspect ratio.
Discover your celebrity doppelgänger with StarByFace!
ChainClarity explains 700+ crypto whitepapers in plain English, with layered summaries, comparisons, research tools, alerts, and a $4.99 Pro plan.
Opus.ai: Revolutionize Your Web Experience