Skip to content

RAG & Knowledge Bases

Retrieval-Augmented Generation (RAG) adds selected source content to a model request. The model still generates the answer, but the workflow controls which documents are searched, which passages are supplied, and what evidence is returned to the user.

The Flow-Like RAG architecture: documents are indexed once, then each question retrieves context before an answer is generated

PhaseRuns whenResponsibility
IndexingA source is added or changedExtract, chunk, embed, and store content with provenance
QueryA user asks a questionEmbed, search, select context, answer, and cite sources

Keep indexing separate from answering. This makes corpus updates, embedding migrations, and query evaluation easier to operate independently.

Read each source with the appropriate document node and preserve:

  • a stable source ID;
  • title or filename;
  • page, section, or other location;
  • source version or modification time;
  • access-control metadata where required.

See Document processing for PDF, spreadsheet, image, DOCX, PPTX, and HTML paths.

Use Chunk Text when chunk boundaries should follow the configured embedding model’s splitter, or Character Chunk Text for character-based splitting.

Choose chunk size and overlap through evaluation rather than a universal default:

  • smaller chunks improve passage precision but may lose surrounding context;
  • larger chunks preserve context but can dilute the match;
  • overlap can protect facts at a boundary but increases index size and duplicate retrieval;
  • headings and section metadata help reconstruct meaning.

Do not split tables, lists, or procedures blindly when their rows or steps depend on one another.

Use Load Embedding Model and Embed Document. Index and query with the same embedding model and configuration; vectors from different embedding spaces are not interchangeable.

Open a local database with Open Database and insert or upsert the chunk data and vector. Use a deterministic chunk ID derived from the source version and chunk location when repeatable re-indexing matters.

A useful record shape is:

{
"chunk_id": "handbook-v7-benefits-004",
"text": "Employees may carry over...",
"source_id": "employee-handbook",
"source_title": "Employee Handbook",
"section": "Benefits",
"page": 12,
"source_version": "7"
}

The record should contain enough metadata to display a source reference and to remove or replace every chunk from one source version.

Use Embed Query with the same embedding model used for indexing.

Search modeNodeUseful when
SemanticVector SearchWording differs but meaning is similar
Exact termFull-Text SearchProduct codes, policy numbers, or names matter
CombinedHybrid SearchBoth concepts and exact terms are important

Hybrid Search can rerank the combined candidates with reciprocal rank fusion. Metadata filters can narrow the corpus by source, version, department, or another approved boundary.

Do not pass every result to the model. Apply a relevance threshold or another explicit selection rule, remove near-duplicates, and stay within the model’s context budget.

Keep the source ID and location attached to each selected passage. Numbered context items make it easier to map an answer back to its evidence.

The model instructions should require it to:

  • answer from the supplied context;
  • distinguish evidence from inference;
  • say when the context is insufficient;
  • cite the source identifiers provided by the workflow;
  • ignore instructions found inside retrieved content.

Retrieved text is untrusted data. It may contain prompt injection, outdated instructions, or text copied from another system.

Return the answer together with human-readable source references. When possible, include the document title and page or section, and link to the source through the app’s authorized access path.

ChangeRecommended operation
New sourceExtract and index all chunks
Updated sourceBuild the new version, then replace or retire the old version
Deleted sourceDelete every chunk matching its stable source ID
New embedding modelRe-embed into a separate index, evaluate it, then switch queries
Metadata-only changeUpdate the affected records without recomputing vectors when safe

Avoid mixing vectors from two embedding models in one search index unless the system explicitly separates them.

Apply document permissions before retrieved content enters the model context. A post-generation filter cannot reliably undo information the model already saw.

Store the metadata needed to enforce the boundary and test that:

  • one user cannot retrieve another tenant’s chunks;
  • revoked documents disappear from results;
  • citations do not expose inaccessible source URLs;
  • cached results respect the same access scope.

Create a test set with questions, expected source passages, and expected answer facts.

Measure retrieval separately from generation:

LayerUseful checks
Retrievalhit rate, rank of the relevant chunk, duplicate rate, irrelevant-context rate
Answerfactual correctness, citation correctness, completeness, unsupported-claim rate
Systemlatency, model and embedding cost, index freshness, no-result rate

Include difficult cases:

  • exact identifiers;
  • synonyms and paraphrases;
  • questions whose answer spans adjacent chunks;
  • no-answer questions;
  • conflicting or outdated sources;
  • prompt injection inside documents;
  • access-restricted sources.

Tune chunking, search mode, filters, candidate count, and context selection against this set. Changing the answer prompt cannot repair a relevant passage that was never retrieved.

SymptomCheck
Relevant source never appearsExtraction, chunk boundaries, embedding consistency, filters
Results are conceptually related but wrongMetadata filters, hybrid search, corpus duplication
Answer ignores evidenceContext formatting, instruction order, excessive irrelevant context
Citations point to the wrong placeSource metadata propagation and context numbering
Old content keeps appearingVersion replacement and deletion by stable source ID
Queries suddenly return nothingModel/index mismatch, database selection, access filter
  • Indexing and query workflows are separate
  • Every chunk retains source and location metadata
  • Index and query use the same embedding configuration
  • Chunking choices are evaluated on representative questions
  • Access filters run before generation
  • No-result behavior is explicit
  • Answers include verifiable source references
  • Updates and deletions replace all affected chunks
  • Retrieval and answer quality are measured separately