
RAG combines document retrieval (semantic search over indexed documents) with generation. The retrieval step provides relevant passages; the LLM conditions on those passages to produce accurate, cited responses — ideal for audits and compliance workflows.


- Indexing: documents from S3, internal wikis, git repos, and ticketing systems are continuously ingested.
- Embeddings: documents are transformed into dense vectors for semantic similarity.
- Retrieval: a query fetches the most relevant passages from the vector store.
- Generation: an LLM uses the retrieved passages as context to produce grounded, cited answers.
Triage checklist (step-by-step)
- Reproduce and log failures:
- Collect representative queries that produced wrong or unverified answers.
- Save model responses and the retrieved passages used for each response.
- Inspect retrieval:
- For each failing query, check the top-K retrieved passages. Are they relevant? Do they cite the correct document and location?
- Evaluate embeddings:
- Recompute similarity distances for expected positive/negative examples.
- If similar documents aren’t near each other, try a higher-quality embedding model.
- Validate ingestion:
- Confirm all sources are indexed and accessible.
- Check for duplicate or fragmented documents caused by inconsistent chunk sizes.
- Improve prompts:
- Force the model to include citations and to say “I don’t know” when evidence is insufficient.
- Monitor and iterate:
- Add a human-in-the-loop review for uncertain cases.
- Track accuracy and citation precision over time.
- Chunking: use semantically coherent chunks (paragraph or section boundaries), not fixed byte sizes.
- Metadata: store and surface source metadata (file path, commit id, timestamp) so answers can be traced.
- Embedding model: benchmark several embedding models on your corpus; quality matters more than cost for accuracy.
- Retrieval settings: tune
top_kand similarity thresholds; sometimes fewer, higher-quality passages are better. - Prompt engineering: require that the model output both an answer and a list of citations with exact offsets.
- Evaluation: build a test set of queries with ground-truth passages and measure retrieval precision, recall, and end-to-end answer accuracy.
When building RAG for sensitive documents (e.g., PII, credentials, proprietary policies), ensure data handling, storage encryption, and access controls meet your compliance requirements. Never send sensitive raw documents to third-party LLM APIs unless contractually and technically permitted.
- Vector databases: Pinecone, Milvus, Weaviate, or FAISS (self-hosted).
- Embedding providers: OpenAI embeddings, Cohere, or open-source encoders (e.g., sentence-transformers).
- Connectors: S3 sync, GitHub/GitLab crawlers, Confluence/Notion export scripts, and ticketing API ingestion.
- Observability: logging of retrieval traces, source citations, and user feedback loops.
- Retrieval-Augmented Generation overview: https://www.deeplearning.ai/blog/retrieval-augmented-generation-rag/
- Vector databases and ANN: https://www.pinecone.io/, https://milvus.io/, https://faiss.ai/
- Prompting best practices: https://platform.openai.com/docs/guides/prompting
Welcome to the lab — reproduce the failures, iterate on ingestion/embeddings/retrieval/prompting, and push the system to >90% accuracy so the business can depend on a single, auditable source of truth.