How to Build a Code Graph With Cognee
Cognee is an open-source Python library that ingests documents into a knowledge graph plus a vector index, then answers questions over both. Install it, point it at a folder, and you get something you can query in plain language without writing a schema for every entity.
For engineering teams, the appealing use is a graph over code plus docs, so a question about a function can pull in the design note that shaped it.
What does Cognee actually build?
Two stores. A vector store holds embeddings of text chunks for similarity search. A graph store holds entities and relationships the pipeline extracts, such as function-calls-function or document-mentions-service. A query can hit either or both.
That combination is the point. Vector search finds similar passages; graph traversal finds connected facts even when the words differ.
How do you run a first pipeline
Roughly:
- Install the package and start the backend with its built-in server command.
- Point it at a source: a folder of Markdown, a PDF, or a code path.
- Run the add step to ingest and extract entities.
- Run the cognify step to build the graph.
- Query in natural language through the search function.
Expect the cognify step to dominate runtime. On a few hundred documents, minutes; on a large repo, hours.
Why does extraction quality vary so much?
Entity extraction is a model call, and models make different choices about granularity. On code, they may key on function names well and class hierarchies poorly. On prose, they handle named entities and miss domain terms.
| Input | Extraction quality |
|---|---|
| Structured Markdown docs | Good |
| Plain PDFs with clean text | Good |
| Scanned PDFs | Poor without OCR |
| Source code, small modules | Medium |
| Large monorepo | Slow, noisy |
Run a 50-file subset first and read the extracted triples. If they look wrong, the full run will be wrong at scale.
Read the graph before you query it. Twenty minutes of eyeballing triples saves a week of trusting bad answers.
What should you decide before ingesting a repo
Chunking. Default chunk sizes work for prose and break functions apart in code. Set a larger chunk with overlap for code paths, smaller for docs.
Also decide what not to ingest: test fixtures, vendored libraries and generated files inflate the graph and skew retrieval. One exclusion list saves a re-run.
How does it compare with a docs assistant
If your need is purely question answering over existing docs, a retrieval assistant like Danswer needs less setup and no graph reasoning. Gain from Cognee’s graph comes when relationships matter: which service depends on which, which doc justified a schema change.
Limitations worth knowing
It is a library, not a product: you own the backend, the cost, and the failures. Extraction calls cost money on hosted models, and re-ingesting after a schema change means re-running cognify. There is no polished UI by default, so non-engineers will not use it directly.
Quick Summary
- Cognee builds a vector index plus a knowledge graph from documents and code.
- Pipeline is add then cognify, then natural-language query.
- Extraction quality depends on input cleanliness and chunk size.
- Test 50 files and read the triples before a full run.
- It is a library with real infrastructure cost; not a turnkey docs assistant.
