Published
RAG Architecture: A Practical Guide to Grounding LLMs in Company Knowledge
How retrieval-augmented generation works end to end: chunking, embeddings, hybrid search, reranking, citations and metrics that show answers can be trusted.
- Written by
- Ali ÖzdurmuşFounder, Veni AI
- Updated
- Reading time
- 6 min read

Retrieval-Augmented Generation (RAG) lets a language model answer from your documents instead of from memory. Before the model writes a word, the system looks up the most relevant passages in your own knowledge base and puts them into the prompt. The result: answers that are current, specific to your company and traceable to a source.
RAG is the backbone of most internal assistants we see in companies: policy and procedure search, product knowledge for sales teams, technical documentation for field service, contract lookup for legal teams.
Why RAG Instead of "Just Asking the Model"
- Currency: models only know what was in their training data. Your price list from last week is not in there.
- Specificity: your internal procedures, product codes and customer terms are not public.
- Traceability: every answer can point to the document and passage it came from.
- Access control: retrieval can respect the same permissions as your document systems.
Core Components
- Ingestion: reads documents from file shares, wikis, ERP/CRM exports, email archives
- Chunking + embedding: splits documents into passages and turns each into a vector
- Index: a vector store (often combined with keyword search)
- Retriever + reranker: finds and orders the most relevant passages
- Generator: the LLM that writes the answer using only the retrieved context
Document → Chunking → Embedding Model → Vector Index
Question → Embedding → Retrieve → Rerank → Prompt + Context → LLM → Answer + CitationsChunking Strategies
- Fixed-size chunking: a fixed token count with overlap. Simple, a reasonable baseline.
- Structure-aware chunking: split on headings, sections, table boundaries. Usually better for policies and manuals.
- Semantic chunking: split where the topic changes.
Typical trade-off:
- Small chunks (256–512 tokens): precise matches, but context can be cut off.
- Large chunks (1,000–2,000 tokens): more context per hit, but more noise in the prompt.
Store the document title, section heading, date and access level as metadata with every chunk. You will need them for filtering and citations.
Choosing an Embedding Model
Current options include Cohere Embed 5, Gemini Embedding 2, Voyage 4 and the open-weights Qwen3-VL-Embedding (which can also embed images). Do not choose from a leaderboard alone. Build a small test set of real questions from your own Turkish and English documents and measure retrieval quality on it. Language coverage and domain vocabulary differ a lot between models.
Retrieval Strategies
Dense retrieval
Similarity between the question vector and passage vectors:
similarity = dot(query_embedding, doc_embedding) / (
norm(query_embedding) * norm(doc_embedding)
)Sparse retrieval (BM25)
Classic keyword matching. Still the best tool for exact terms: product codes, article numbers, legal references.
Hybrid retrieval
Combine both:
final_score = α × dense_score + (1 - α) × sparse_scoreIn practice hybrid retrieval beats either method alone on company documents, because questions mix natural language with exact identifiers.
Graph-enriched retrieval
Some questions depend on relationships, not just similar text: "Which suppliers deliver parts used in product X?" Adding a knowledge graph next to the vector index lets you:
- start from the passages vector search finds,
- follow links to related entities (product → part → supplier → contract),
- add those connected passages to the context.
Use it where relationships carry the answer. For plain document lookup, hybrid search is usually enough.
Reranking
The first retrieval pass is optimized for speed. A reranker re-orders the top candidates with a more precise model:
- Cross-encoder rerankers: high accuracy, slower
- Late-interaction models (ColBERT style): a middle ground
- Hosted rerank APIs: for example Cohere Rerank 4 or Voyage rerank-3
A common setup: retrieve 30–50 candidates, rerank, keep the top 5–8.
Multimodal Sources
Company knowledge is not only text. Scanned contracts, product photos, diagrams, recorded calls and slides all carry information.
- Separate pipelines per modality: OCR or a vision model for scans, transcription for audio, region-based chunks for images and diagrams.
- Shared index: store everything as text plus, where useful, image embeddings in the same index, with the modality as metadata.
- Test each modality on its own before you mix them. A weak OCR step will quietly ruin answer quality.
Citations and Source Transparency
Make citations a core part of the experience, not a footnote:
- Every answer lists the documents and sections it used.
- Users can open the source passage in one click.
- If retrieval finds nothing relevant, the assistant says so instead of guessing.
System: Answer only from the context below. Cite sources as [doc_id §section].
If the context does not contain the answer, say "I could not find this in the documents."Enterprise Architecture Example
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ User │────▶│ API GW │────▶│ RAG Service │
└─────────────┘ └─────────────┘ └──────┬──────┘
│
┌─────────────┐ ┌──────▼──────┐
│ LLM API │◀────│ Retriever │
└─────────────┘ └──────┬──────┘
│
┌─────────────────┼─────────────────┐
│ │ │
┌──────▼──────┐ ┌──────▼──────┐ ┌──────▼──────┐
│ Vector Index│ │ Keyword/BM25│ │ Graph Store │
└─────────────┘ └─────────────┘ └─────────────┘Security Considerations
- Data isolation: separate indexes or namespaces per tenant or business unit
- Document-level access control: filter by the user's permissions at retrieval time, not after generation
- Audit logging: record questions, retrieved sources and answers
- Personal data: mask or exclude personal data that the use case does not need (KVKK and GDPR both expect data minimization)
Measuring Quality
Retrieval metrics
- Recall@K: how many of the relevant passages appear in the top K
- Precision@K: how many of the top K are actually relevant
- MRR (Mean Reciprocal Rank): how high the first correct passage ranks
Answer metrics
- Faithfulness: does the answer stay within the retrieved sources?
- Relevance: does it answer the question that was asked?
- Latency: total response time
Build a simple A/B evaluation set early, especially when you compare dense-only, hybrid and graph-enriched retrieval. Treat retrieval quality as a product metric, not just an engineering detail.
Common Problems and Fixes
| Problem | Typical fix |
|---|---|
| Relevant document exists but is not found | Hybrid retrieval, better chunking, richer metadata |
| Answer contains facts not in the sources | Stricter prompt, mandatory citations, lower temperature |
| Slow responses | Caching, fewer candidates before reranking, async retrieval |
| Outdated answers | Scheduled re-ingestion, document dates in metadata |
Summary
A good RAG system is mostly careful plumbing: clean ingestion, sensible chunks, hybrid retrieval, reranking and citations, all measured against real questions. Multimodal sources and graph relationships are worth adding once the text pipeline is solid.
Veni AI builds RAG-based assistants on top of companies' own documents and systems, with access control and citations built in. See our services or tell us about your knowledge base.


