Helm7

GraphRAG on Plain Postgres, No Graph Database

The Helm7 team · Published 16 November 2026 · 8 min read

graphrag: a metal structure of straight beams joined by red spheres, like nodes and edges
Photo by Brett Sayles on Pexels

GraphRAG sounds like it needs a graph database, a pipeline of language-model calls and a new thing to run. For most applications it does not. If your data already has foreign keys, you can retrieve by meaning and then follow the relationships in plain Postgres, using pgvector and one recursive query. Here is the pattern, the SQL, and the kind of question where the heavier Microsoft approach is the better tool.

In short

  • GraphRAG is both a Microsoft method built on community summaries and a general idea: retrieve by meaning, then follow relationships.
  • On data that already has foreign keys, the general idea is a pgvector search plus one recursive query. No graph database and no extraction step.
  • Cap the walk by depth, by fan-out per row and by total rows, and put a LIMIT on the output.
  • Use the Microsoft approach for global, thematic questions over unstructured text. Expect model calls over the whole corpus at index time.
  • Run the traversal as the end user so row security applies, and rank after filtering so hidden rows cannot influence results.

What does GraphRAG actually mean?

The name covers two different things, and mixing them up is where most of the confusion starts. One is a specific method from Microsoft Research. The other is a general idea: when you retrieve text for a language model, use the links between facts as well as their similarity to the question.

Microsoft's documentation calls its version a structured, hierarchical approach to retrieval augmented generation. It builds a knowledge graph from your text, groups the graph into communities, and writes a summary of each community. The same documentation says baseline RAG struggles to connect the dots, which is the problem both ideas set out to fix.

Plain vector search finds the passages that sound like the question. It does not know that the contract you found belongs to a customer, that the customer has three open tickets, or that one ticket was escalated last week. Those facts sit in other rows. Similarity alone will not reach them.

Retrieve by meaning, then follow the links

The lightweight version of graphrag has two steps. First, find a handful of starting points by meaning. Second, walk outwards along known relationships for a step or two and collect what you meet. Then hand the lot to the model.

  • Seed: embed the question, find the five or ten nearest rows. Mix in keyword matching so exact names and codes still win.
  • Expand: from each seed, follow foreign keys and labelled links for one to three hops, with a cap on how many rows each hop may add.
  • Rank and trim: score what you gathered, drop the weak branches, and keep what fits the model's context window.

Notice what is missing. There is no extraction step that asks a model to read every document and write down entities. If your relationships already exist as foreign keys, they were extracted when somebody designed the schema. That is cheaper and, for structured business data, usually more accurate than a model's guess at what links to what.

How does GraphRAG map onto pgvector and SQL?

Every moving part has a home in Postgres you may already be running. The table shows the mapping we use when we explain this to people who have only seen the diagrams.

GraphRAG ideas and where each one lives in a plain Postgres database
GraphRAG ideaIn PostgresNotes
Embedding of a chunkA vector or halfvec column from pgvectorUp to 2,000 dimensions can be indexed for vector, 4,000 for halfvec
Nearest-neighbour searchORDER BY embedding <=> query LIMIT kExact by default; HNSW or IVFFlat makes it approximate
Keyword matchA tsvector column with a GIN indexCatches names, codes and rare terms that embeddings blur
Entity and relationshipRows and foreign keys, or an edges tableAn edges table adds labelled links such as "supersedes"
Multi-hop traversalWITH RECURSIVE with a CYCLE clauseDepth and fan-out caps keep it bounded
PermissionsRow level security policiesApplied to every row the walk touches

The pgvector README describes itself as open-source vector similarity search for Postgres. It supports cosine distance with the <=> operator, and by default it does an exact search with perfect recall. Add an HNSW or IVFFlat index and it becomes approximate, trading a little recall for speed. For a table under a few tens of thousands of rows, the exact scan is often fast enough that you never need the index.

What does the query look like?

Here is the whole pattern in one statement. It finds five seed rows by cosine distance, then walks up to two hops along an edges table. The CYCLE clause stops the walk from going round in circles. Parameter $1 is the question's embedding.

WITH RECURSIVE seeds AS (
  SELECT id FROM documents
  ORDER BY embedding <=> $1
  LIMIT 5
), walk(id, depth) AS (
  SELECT id, 0 FROM seeds
  UNION ALL
  SELECT e.dst_id, w.depth + 1
  FROM walk w
  JOIN edges e ON e.src_id = w.id
  WHERE w.depth < 2
) CYCLE id SET is_cycle USING path
SELECT d.id, d.title, min(w.depth) AS hops
FROM walk w
JOIN documents d ON d.id = w.id
WHERE NOT w.is_cycle
GROUP BY d.id, d.title
ORDER BY hops, d.title
LIMIT 40;
Semantic start, two-hop walk, bounded output

Two things make this safe to run in production. The depth test in the recursive term caps the walk, and the final LIMIT caps what comes back. We go through the recursive part line by line in recursive CTEs as graph traversal, including how to cap fan-out per row so one very popular node cannot flood the result.

If your edges are only foreign keys, you do not need an edges table. Join on the foreign key columns in the recursive term. An edges table earns its place when you want labelled, row-to-row links that no column expresses.

Why mix keyword and vector search for the seeds?

Embeddings are good at meaning and poor at exactness. Ask for invoice INV-20431 and a vector search may return invoices that merely look similar. Full-text search gets it right immediately. Ask for something vague like the trouble with the Lyon deployment and the situation reverses.

Reciprocal rank fusion is the usual way to combine the two lists. Each result scores one divided by a constant plus its rank in each list, and the scores are added. It needs no tuning of weights, because it uses positions, not raw scores that live on different scales. We use a constant of 60.

One detail matters if people see different data. Compute the ranking after the rows are filtered by permission, not before. Otherwise the position of a visible row would depend on how many hidden ones outranked it, which leaks a little about data the reader should not know exists.

When is Microsoft's GraphRAG worth it instead?

When the question is about the whole collection, not a few of its members. The Microsoft paper is blunt about the gap it targets.

“RAG fails on global questions directed at an entire text corpus.”
Abstract of the GraphRAG paper, Microsoft Research, arXiv 2404.16130

A question such as what are the main themes across these 10,000 support conversations cannot be answered by retrieving ten rows and walking a few hops. The answer is spread across everything. The paper's approach builds a graph of entities and relationships with a language model, groups closely related entities into communities, and writes a summary of each community ahead of time. At question time, each summary produces a partial answer and those are combined into one.

Which approach suits which question
Question typeExampleBetter fit
Specific, with linksWhich open tickets does the customer who signed this contract have?Semantic start plus SQL traversal
Specific, exactWhat happened to order 8841?Keyword match, then a join
Global, thematicWhat are the recurring complaints across all feedback?Community summaries
Unstructured text, no schemaHow do these 500 reports relate to each other?Community summaries, after entity extraction

The cost is real. The paper's index is built in two stages that both rely on a language model: one to pull out the graph, one to summarise the groups. It is worth paying when your data is mostly free text and the questions are broad. It is poor value when your data is already rows with keys and the questions are about specific things.

What about permissions and stale links?

This is where keeping graphrag inside one database pays off. Postgres row security policies restrict, on a per-user basis, which rows a query can return. If the walk runs as the end user's database role, a hidden row is never returned and, if you write the join correctly, never passed through on the way to another row.

A separate graph store has to copy those rules or get them wrong. It also has to be kept in step with the source tables. A walk over live foreign keys cannot go stale, because it reads the same rows the application writes. The derived part, the embeddings, is the only thing that needs a sync job, and that job is small.

The trade-off is that Postgres is not a graph engine. Very deep walks across millions of edges are where a dedicated graph database starts to win. Most application questions stop at two or three. If yours do not, say so in your requirements before you pick a tool.

How Helm7 does this, and what to compare it with

We built this pattern into the Helm7 databases page as two switches you turn on per database: semantic search per table, and relationships. Nothing is copied out of your Postgres. Helm7 adds its own schema inside the database, reads foreign keys as edges, and compiles a traversal to a single recursive query with a depth cap of 4, a fan-out of 50 per row per hop, a 500-node cap and a five-second timeout. It runs as your app's own role, so row security applies.

Search fuses full-text and vector results with reciprocal rank fusion at a constant of 60, after joining back to your table under your role. The details are in the API reference. It is one option. If you want to own the SQL, the example above runs on any Postgres with pgvector. If your problem is global and thematic, look at Microsoft's open-source GraphRAG project. And if you are choosing a store for memory generally, which database for LLM memory compares the options.

Common questions

  • Do I need a graph database for GraphRAG?

    Not for most applications. If your relationships are foreign keys or an edges table, a recursive query in Postgres walks them for one to three hops. A graph database helps when walks are deep, across very large edge sets.

  • What is the difference between GraphRAG and normal RAG?

    Normal RAG retrieves the passages most similar to the question. GraphRAG adds the relationships between facts, either by walking links from the first results or, in Microsoft's method, by summarising communities in a knowledge graph.

  • Is Microsoft GraphRAG expensive to run?

    Indexing is the cost. The method uses a language model to extract entities and relationships, then to summarise each community. That means many model calls over the whole corpus, so it suits collections that change slowly.

  • Does pgvector scale far enough for this?

    For many applications, yes. pgvector does exact search by default and supports HNSW and IVFFlat indexes for larger tables. Embeddings can be indexed up to 2,000 dimensions for the vector type.

Sources

  1. Microsoft GraphRAG documentation
  2. From Local to Global: a graph RAG approach to query-focused summarization (arXiv 2404.16130)
  3. PostgreSQL documentation: WITH queries
  4. pgvector on GitHub
  5. PostgreSQL documentation: row security policies

Run your entire app stack, end to end, from $12 a month.

App, Postgres, auth, storage, jobs and domains on one platform, planned and priced before anything changes.

More from the blog