How GraphRAG differs from plain vector RAG
Plain vector RAG
The basic idea: encode every passage of a document as a vector, encode the question as a vector, then take the passages whose vectors are closest. Closeness is usually measured with cosine similarity:
It is fast and simple, and it fits questions whose answer sits neatly inside a few passages.
import numpy as np
def cosine(q: np.ndarray, d: np.ndarray) -> float:
return float(q @ d / (np.linalg.norm(q) * np.linalg.norm(d)))
def top_k(query_vec, chunk_vecs, k=5):
scores = [cosine(query_vec, v) for v in chunk_vecs]
return sorted(range(len(scores)), key=scores.__getitem__, reverse=True)[:k]Where plain vectors are weak
For questions that need to connect information from several places, such as "who has worked with both system A and system B?", the relevant passages may not resemble the question semantically, so they are not retrieved together.
GraphRAG
GraphRAG extracts entities and relations from the documents to build a knowledge graph. At query time it finds the entities in the question and walks the neighbouring nodes, which collects structured context even when the pieces of information live in different documents.
The trade-offs
- Building the graph costs an extra extraction step (often an LLM call) and is harder to keep up to date when documents change.
- Quality depends on extracting the entities correctly.
- For simple questions, plain vectors are still cheap and good enough.
So there is no need to pick one: many real systems combine both.