# How CodeGraph Is Indexed and What Analysis It Performs in TencentDB Agent Memory

> Discover how CodeGraph is indexed in TencentDB Agent Memory for dependency traversal, call-graph exploration, and impact analysis. Learn about its unique ID system and memory persistence.

- Repository: [Tencent Cloud/TencentDB-Agent-Memory](https://github.com/TencentCloud/TencentDB-Agent-Memory)
- Tags: internals
- Published: 2026-08-29

---

**The CodeGraph in TencentDB Agent Memory is built by parsing source files into nodes and edges, assigning each entity a unique CodeGraph ID, and persisting the structure in MemoryCore to enable dependency traversal, call-graph exploration, and impact analysis.**

The TencentDB Agent Memory platform maintains a structured **CodeGraph** representation that maps every module, class, function, and variable in your repository. During the **indexing** phase, the system parses your source tree to construct this graph, storing it in the **MemoryCore** service where it can be queried by the **MemoryPanel** front-end without re-parsing code.

## How the CodeGraph Is Indexed

### Source Tree Parsing and Node Extraction

The indexing process begins when the indexer walks the project’s source tree and feeds each file through a language-specific parser. For TypeScript files, the system uses the TypeScript parser; other languages use their respective parsers. For every syntactic construct encountered—whether a function declaration, class definition, variable, or module—the indexer extracts a **node** that captures the entity’s metadata, including file path, line range, and documentation comments.

### Edge Creation and Relationship Mapping

Once nodes are identified, the indexer creates **edges** that codify relationships between entities. The graph tracks several relationship types:

- **calls** – links a function to the functions it invokes
- **defines** – connects a module to the symbols it exports
- **imports** – records module dependencies and `require` statements
- **inherits** – maps class extension and interface implementation hierarchies

### CodeGraph ID Assignment and Persistence

Every node receives a unique identifier known as the **CodeGraph ID** (`codeGraphId`) that remains stable across the entire repository. This UUID is stored alongside the entity’s metadata in the **MemoryCore** service, allowing the system to reference specific code elements unambiguously. The persisted graph structure eliminates the need to re-parse source files when running analyses.

### UI Integration and Localization

The front-end exposes the CodeGraph through localized UI strings defined in the internationalization files:

- `code.table.codeGraphId` – renders the "Code Graph ID" column header in data tables
- `code.detail.breadcrumb` – displays "Code Graph" in navigation breadcrumbs when drilling into a node
- `allocAsset.codeGraph` – labels the asset type when allocating resources to graph entities

These strings are defined in [`MemoryPanel/web/src/i18n/en-US.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryPanel/web/src/i18n/en-US.ts) (lines 367–385, 783) and [`MemoryPanel/web/src/i18n/zh-CN.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryPanel/web/src/i18n/zh-CN.ts) (line 355), ensuring consistent terminology across English and Chinese interfaces.

## What Analysis the CodeGraph Can Perform

Once materialized, the graph supports sophisticated static-analysis queries through the **MemoryCore** utilities. The following analyses operate directly on the stored graph structure without touching the filesystem.

### Dependency Traversal

Follow **import** and **require** edges transitively to enumerate the complete dependency tree of a module. This reveals both direct imports and nested dependencies that a file relies upon.

### Call-Graph Exploration

Navigate **calls** edges bidirectionally to understand execution flow:

- **Caller-side analysis**: identify which functions invoke a specific target function
- **Callee-side analysis**: discover which functions are invoked by a target function

### Inheritance and Interface Mapping

Trace **extends** and **implements** edges to map class hierarchies, locate method overrides, and identify which classes conform to specific interfaces across the codebase.

### Reference Search

Locate every use-site of a variable, constant, or class by traversing **defines** and **calls** edges. This provides precise find-all-references functionality without text-search false positives.

### Impact Analysis

Combine multiple edge types to compute the **blast radius** of a proposed change. By traversing call-graphs and dependency edges from a starting function, the system can enumerate all downstream functions and modules that might be affected by a modification.

## Implementation in MemoryCore

The analysis capabilities are powered by utility modules located in `MemoryCore/src/utils/`. These provide generic graph-traversal primitives used by higher-level services:

- **[`pipeline-manager.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/pipeline-manager.ts)** – core helpers such as `getGraphNode` and `fetchNodeById` that retrieve nodes by their `codeGraphId` and expose predecessor/successor edge arrays
- **[`stateful-pipeline-manager.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/stateful-pipeline-manager.ts)** – provides stateful pipelines that maintain context across multi-step analysis queries
- **[`session-filter.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/session-filter.ts)** – supplies filtering logic to scope traversals to specific user sessions or project subsets

When the MemoryPanel front-end triggers an analysis—handled in [`MemoryPanel/web/src/turnSeq.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryPanel/web/src/turnSeq.ts)—it invokes these utilities to execute the query against the stored graph.

## Practical Code Examples

### Retrieving a Node and Listing Imports

The following TypeScript snippet demonstrates how to fetch a graph node by its unique ID and extract its direct dependencies:

```typescript
import { fetchNodeById } from 'memory-core/src/utils/pipeline-manager';

// Retrieve node by its unique Code Graph ID
const graphNode = await fetchNodeById('c7f3a9e2-1b4d-4e8a-9d5f-2b6c7d1e9f34');

// List imported modules (edges of type 'imports')
const imports = graphNode.successors
  .filter(edge => edge.type === 'imports')
  .map(edge => edge.target);

console.log('Direct imports:', imports);

```

### Running Impact Analysis for a Function Change

To determine which functions might break when modifying a specific function, use the transitive callee utility:

```typescript
import { getTransitiveCallees } from 'memory-core/src/utils/pipeline-manager';

/**
 * Returns the set of functions that may be affected by a change
 * to the function identified by `codeGraphId`.
 */
async function impactAnalysis(codeGraphId: string) {
  const affected = await getTransitiveCallees(codeGraphId);
  return affected.map(node => ({
    id: node.id,
    name: node.metadata.name,
    file: node.metadata.filePath,
  }));
}

// Example usage
impactAnalysis('a3d5b9c0-7e12-4f6a-9b8c-1d2e3f4a5b6c')
  .then(res => console.table(res));

```

## Summary

- The **CodeGraph** is constructed during indexing by parsing source files into nodes (entities) and edges (relationships like **calls**, **imports**, and **inherits**).
- Each entity receives a unique **`codeGraphId`** that enables stable referencing across the **MemoryCore** persistence layer and the **MemoryPanel** UI.
- The graph supports five primary **analyses**: dependency traversal, call-graph exploration, inheritance mapping, reference search, and impact analysis.
- Core traversal logic resides in [`MemoryCore/src/utils/pipeline-manager.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/src/utils/pipeline-manager.ts), with stateful pipelines and session filtering provided by adjacent utility modules.
- UI localization for CodeGraph elements is defined in [`MemoryPanel/web/src/i18n/en-US.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryPanel/web/src/i18n/en-US.ts) and [`zh-CN.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/zh-CN.ts).

## Frequently Asked Questions

### What is a CodeGraph ID?

A **CodeGraph ID** is a UUID assigned to every entity (function, class, variable, or module) during the indexing process. It serves as the primary key in the graph database and allows the **MemoryPanel** UI and **MemoryCore** APIs to reference specific code elements unambiguously across the entire repository.

### How does the indexer handle different programming languages?

The indexer uses language-specific parsers to process files according to their extension. For example, it employs the TypeScript parser for `.ts` files, while other languages use their respective parsers. Each parser extracts syntactic constructs that are normalized into the common graph node and edge schema used by the CodeGraph.

### What types of relationships does the CodeGraph track?

The graph tracks **calls** (function invocations), **defines** (symbol declarations), **imports** (module dependencies), and **inherits** (class extension and interface implementation). These edges enable precise traversal for dependency analysis, call-graph exploration, and inheritance mapping without text-based searching.

### How can I perform impact analysis to see what breaks if I change a function?

Use the `getTransitiveCallees` function from [`MemoryCore/src/utils/pipeline-manager.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/MemoryCore/src/utils/pipeline-manager.ts). Pass the target function’s `codeGraphId` to retrieve all downstream functions reachable through **calls** edges. The return set represents the complete blast radius of the proposed change, including every function that might be affected by modifying the target.