Step-by-step guide to building code-level graphs from repositories
A minimal guide to building a code-level graph from a repository and searching it. The pipeline parses your repo, extracts code entities and dependencies, and optionally processes non-code docs alongside.Before you start:
Complete Quickstart to understand basic operations
import asyncioimport cogneefrom cognee import SearchTypefrom cognee.api.v1.cognify.code_graph_pipeline import run_code_graph_pipelineasync def main(): repo_path = "/path/to/your/repo" # folder root # Build the code graph (code only) async for _ in run_code_graph_pipeline(repo_path, include_docs=False): pass # Ask a code question results = await cognee.search(query_type=SearchType.GRAPH_COMPLETION, query_text="Where is Foo used?") print(results)asyncio.run(main())
This simple example uses a basic repository for demonstration. In practice, you can process large codebases with multiple languages and complex dependency structures.
async for _ in run_code_graph_pipeline(repo_path, include_docs=False): pass
This scans your repository for supported languages and builds code nodes/edges. The pipeline handles file parsing, symbol extraction, and dependency analysis automatically.
results = await cognee.search(query_type=SearchType.GRAPH_COMPLETION, query_text="Where is Foo used?")
Use SearchType.GRAPH_COMPLETION to ask code-aware questions about your repository. This searches through the extracted code structure, not just text content.