Skip to content
envexa

AI Engineering

RAG architecture: the decisions that matter before you pick a vector database

Retrieval-augmented generation succeeds or fails on chunking, retrieval quality and evaluation, not on your vector database choice. A practical guide.

By Envexa Engineering7 min read

Most conversations about retrieval-augmented generation (RAG) begin with tooling: which vector database, which embedding model, which framework. In our experience these are the least consequential decisions. The quality of a RAG system is determined earlier, by what you index, how you split it, how you retrieve it, and whether you can measure the result.

What RAG is solving

A language model only knows its training data and whatever is in its prompt. RAG fetches relevant passages from your own documents at question time and places them in the prompt, so that answers are based on current, private sources and can cite them. That gives you three things fine-tuning does not: freshness (update a document, and answers change), attribution (show the passage), and access control (retrieve only what this user may see).

Decision 1: what a chunk is

Chunking is the highest-leverage choice. Fixed-size windows are easy but cut tables, lists and arguments in half. Prefer chunks that follow the document's structure: headings, sections, clauses, table rows. Keep the heading path with each chunk, for example Pricing > Refunds > Annual plans, so that a chunk still makes sense when retrieved alone.

  • Use structure-aware splitting first, with a size cap as a fallback.
  • Add modest overlap only where meaning crosses boundaries.
  • Store metadata (source, section, date, permissions) with every chunk. You will need it for filtering and citations.

Decision 2: how you retrieve

Pure vector search finds passages that are semantically similar; it is weaker on exact identifiers, product codes and rare terms. Keyword search (BM25) has the opposite profile. Hybrid retrieval, combining both and merging results, is a robust default. A reranking step, where a smaller model scores the top candidates against the question, often improves precision more than any change to the embedding model.

question
  → metadata filter (tenant, permissions, date)
  → vector search (top 30) + keyword search (top 30)
  → merge and deduplicate
  → rerank (top 5–8)
  → prompt with passages and instructions to cite
  → answer + citations

Decision 3: what the model is allowed to say

Instruct the model to answer only from the supplied passages and to say so when they are insufficient. Require citations, ideally as passage identifiers that your code validates, not free-text references. If an answer cites a passage that was not retrieved, treat it as a failure. These constraints reduce, but do not eliminate, unsupported claims. Which is why evaluation matters.

Decision 4: how you will know it works

Build a small evaluation set before you tune anything: 30 to 100 real questions with the passages that should answer them. Measure retrieval separately from generation. Retrieval metrics (is a correct passage in the top results?) tell you whether the problem is search or the model. Then check answers for faithfulness to the sources. Run the set on every change to chunking, prompts or models.

Where the vector database fits

For many products, PostgreSQL with the pgvector extension is enough: embeddings live next to your documents, permissions and audit logs, and one transaction covers all of it. Dedicated vector databases earn their place at large scale or with specialised indexing needs. Decide this last, and keep it behind an interface so you can change your mind.

A checklist

  1. Do chunks follow document structure and carry metadata?
  2. Is retrieval hybrid, with a reranker if precision matters?
  3. Are permissions enforced at retrieval time, not after generation?
  4. Do answers cite validated passage identifiers?
  5. Is there an evaluation set, and does it run on every change?

Get these right, and the choice of vector store becomes an operational detail. Get them wrong, and no database will rescue the results.

RAGRetrievalEvaluationLLMs

Building something like this?

We are happy to review your architecture or help you build it.