> ## Documentation Index
> Fetch the complete documentation index at: https://vecgrep.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# index_graph

> Build a knowledge graph of a codebase using AST analysis

## Overview

Walks a project directory and extracts a knowledge graph using tree-sitter AST analysis — no LLM required. Nodes represent structural units (files, functions, classes, methods); edges represent relationships (contains, calls, imports, inherits).

The graph is persisted as `graph.json` alongside the vector index and is used by `search_graph` and `graph_neighbors`. It is also blended into results by `hybrid_search` when present.

## Parameters

| Parameter | Type      | Default  | Description                                              |
| --------- | --------- | -------- | -------------------------------------------------------- |
| `path`    | `string`  | required | Absolute path to the codebase root directory             |
| `force`   | `boolean` | `false`  | If `true`, rebuilds the graph even if one already exists |

## Example

```
index_graph("/path/to/myproject")
→ "Graph built for /path/to/myproject: 496 nodes, 1251 edges, 35 files processed."
```

Rebuild after a major refactor:

```
index_graph("/path/to/myproject", force=True)
```

## Node kinds

| Kind       | Description                          |
| ---------- | ------------------------------------ |
| `file`     | A source file                        |
| `function` | A top-level or module-level function |
| `class`    | A class definition                   |
| `method`   | A method inside a class              |

## Edge kinds

| Kind       | Description                           |
| ---------- | ------------------------------------- |
| `contains` | A file or class contains a child node |
| `calls`    | A function or method calls another    |
| `imports`  | A file imports another module         |
| `inherits` | A class inherits from another         |

## Notes

* Graph is stored at `~/.vecgrep/<project_hash>/graph.json`
* Independent of the vector index — can be run before or after `index_codebase`
* Runs entirely locally — no network calls, no LLM
* `hybrid_search` degrades gracefully to pure vector search if no graph index exists
* Use `force=True` after significant refactors to rebuild from scratch
