Skip to content

RAG (Retrieval-Augmented Generation)

Short

RAG is an approach where neural networks provide a 'cheat sheet' before answering: a relevant snippet from an external knowledge base found by semantic search.

Why is it needed

When companies want a neural network to answer based on their internal documents, the first thought is 'we need to fine-tune it'. This is a mistake: fine-tuning changes the model's style, format, and behavior, but is not suitable for memorizing new precise facts. For working with facts, RAG is used.

How it works: a 3-step process

  1. Retrieval (Search). The user asks a question ("What is the warranty on our engines?"). The system searches for a relevant snippet in the company's files/databases.
  2. Augmentation (Enrichment). The found snippet is inserted directly into the prompt: "Here is an excerpt from the regulation: [text]. Answer the user based on this."
  3. Generation (Generation). LLM reads the fresh 'cheat sheet' and provides a precise, verifiable answer.

What does it have to do with vector databases

A classical database searches for exact matches ("cat" won't find "kitten"). A vector database (Pinecone, Qdrant, ChromaDB, Milvus) searches by semantic similarity.

A special neural network-embedder converts text into a vector—a long list of coordinates like [0.23, -0.81, 0.45, ...]. In this 'semantic space', vectors for words like 'king' and 'monarch' are close together, while 'apple' is far away. A vector database stores these coordinates and, upon a query, finds semantically similar document fragments.

Traditional DB (SQL) Vector DB
Type of search Exact text match Semantic similarity search
Finds 'kitten' for the query 'cat' No Yes
Typical use case Storing structured data RAG, semantic search

See also