optimize-retrieval-latency
Skill8 starsChanged 7 months agoMITView on GitHub
Reduce retrieval latency with caching, batching, and index-level optimization.
In this repository39 other files it gives its agents.
- AGENTS.mdAGENTS.md
- rag-skillsSkill
- choosing-a-chunking-frameworkSkill
- contextual-chunk-headersSkill
- hierarchical-chunkingSkill
- semantic-chunkingSkill
- chunkingSkill
- sliding-window-chunkingSkill
- rag-for-code-documentationSkill
- rag-for-multimodal-contentSkill
- data-type-handlingSkill
- index-versioning-and-reindexingSkill
- production-rag-deploymentSkill
- deploymentSkill
- generation-evaluation-metricsSkill
- rag-evaluation-frameworksSkill
- retrieval-evaluation-metricsSkill
- evaluation-metricsSkill
- performance-optimizationSkill
- agentic-rag-routingSkill
- multi-agent-rag-orchestrationSkill
- rag-agentsSkill
- adaptive-retrievalSkill
- context-enrichment-windowSkill
- crag-corrective-ragSkill
- explainable-retrievalSkill
- graph-ragSkill
- hybrid-search-bm25-denseSkill
- hyde-hypothetical-document-embeddingsSkill
- hype-hypothetical-prompt-embeddingsSkill
- multi-pass-retrieval-with-rerankingSkill
- query-transformation-strategiesSkill
- raptor-hierarchical-retrievalSkill
- self-ragSkill
- retrieval-strategiesSkill
- choosing-vector-db-by-datatypeSkill
- qdrant-for-production-ragSkill
- qdrant-setup-ragSkill
- vector-databasesSkill
The file
We split this skill into the rules it gives an agent
2 rules. About 0 are common, 2 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈2
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 69
When user experience is critical
- Distinctive: line 76
When accuracy is more important than speed
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Overview
Optimizing RAG retrieval latency is critical for production applications where user experience depends on fast response times. This skill covers techniques to reduce query latency at every stage: indexing, embedding generation, search execution, and result processing.
Problem Statement
RAG systems often have latency issues:
- Vector search operations take hundreds of milliseconds
- Embedding generation adds significant per-query overhead
- Network round trips between services compound delays
- Cold starts cause unpredictable latency spikes
- Trade-offs between accuracy and speed are unclear
Key Concepts
- Query Path: Full journey from user request to retrieved results
- Hot Path Optimization: Focus on frequently executed operations
- Cold Path: Infrequent operations where accuracy matters more than speed
- Caching Strategies: Multi-level caching for repeated queries and embeddings
- Index Tuning: Balancing recall, build time, and search speed
Implementation Guide
Step 1: Measure Current Performance
Establish baseline measurements before optimization.
Why: You can't optimize what you don't measure. Profiling reveals the actual bottlenecks rather than assumptions.
Step 2: Optimize Embedding Generation
Reduce the overhead of generating query embeddings.
Why: Embedding generation is often the bottleneck - caching reduces this overhead for repeated queries.
Step 3: Optimize Vector Database Operations
Tune indexing and search parameters for latency.
Why: Index parameters directly impact search latency, lower ef values reduce search time at the cost of recall.
Step 4: Implement Multi-Level Caching
Cache at multiple levels to reduce redundant work.
Why: Multi-level caching reduces computation for repeated queries without sacrificing freshness for unique queries.
Step 5: Optimize Result Processing
Stream results and minimize post-processing overhead.
Why: Streaming reduces memory usage and allows users to see results sooner, improving perceived latency.
Step 6: Implement Query Prioritization
Prioritize and batch queries for better resource utilization.
Why: Query prioritization ensures important queries get resources first and reduces contention.
Useful references include the Qdrant production guide, Qdrant snapshots concept, ANN Benchmarks, and AWS caching best practices.
When to Use This Skill
- Production RAG systems with latency SLAs
- High-traffic applications (> 100 QPS)
- When user experience is critical
- Systems with repeat queries
- Resource-constrained environments
When NOT to Use This Skill
- Early prototyping (premature optimization)
- Very low traffic (< 1 QPS)
- When accuracy is more important than speed
- For one-off batch operations
Related Skills
- Qdrant for Production RAG - Production setup
- Multi-Pass Retrieval with Reranking - Two-stage optimization
- Hybrid Search BM25 Dense - Query optimization
Metrics & Success Criteria
- End-to-End Latency: P50 < 100ms, P99 < 500ms for typical queries
- Cache Hit Rate: > 60% for common queries
- Throughput: > 100 QPS per instance
- Recall Degradation: < 5% vs. unoptimized baseline
- Resource Efficiency: CPU < 80%, Memory usage stable
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

