# What Is MemoryKnowledge in TencentDB Agent Memory: Purpose and Architecture

> Discover MemoryKnowledge in TencentDB Agent Memory. Access reusable Wiki pages, Code-Graph indexes, and Skills via a unified API for efficient retrieval of structured documentation and code intelligence.

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

---

**MemoryKnowledge is the core knowledge-service component of TencentDB Agent Memory that supplies reusable, versioned "memory assets"—including Wiki pages, Code-Graph indexes, and Skills—via a unified `/v3` API, enabling agents to retrieve structured documentation and code intelligence on demand instead of re-processing raw documents or repeating previous work.**

MemoryKnowledge serves as the central knowledge layer within the `TencentCloud/TencentDB-Agent-Memory` repository. It transforms raw project documentation and source code into searchable, ACL-protected assets that multiple agents can query through a standardized interface. By treating knowledge as portable, indexed assets rather than ephemeral context, the system eliminates redundant computation and reduces LLM token consumption across team workflows.

## The Core Purpose of MemoryKnowledge

MemoryKnowledge operates as a **standalone knowledge service** that hosts both LLM-Wiki and Code-Graph assets under a single OpenAPI specification. According to [`/MemoryKnowledge/openapi.yaml`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main//MemoryKnowledge/openapi.yaml), the service exposes 28 endpoints for managing and querying code repositories and wiki knowledge bases, providing a unified interface for agent-tool discovery.

The architecture follows a **tool-style invocation** pattern. Agents first discover available capabilities via `/v3/tools/list`, then retrieve specific knowledge through `/v3/tools/call` endpoints. This design keeps LLM context windows small by allowing agents to fetch only the precise asset IDs—such as `wiki-9c1f2b` or `cg-7e3d10`—required for the current task, rather than ingesting entire documentation sets or source trees.

## Architecture and Key Design Principles

### Asset-Centric Design with Global IDs

Every piece of information in MemoryKnowledge is stored as a **memory asset** with a globally unique, immutable ID. As defined in [`/MemoryKnowledge/openapi.yaml`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main//MemoryKnowledge/openapi.yaml), assets use prefixed identifiers like `wiki_id` and `code_graph_id` that are versioned, owned, and ACL-controlled. This makes knowledge safely shareable across teams and agents while maintaining referential integrity.

### Eliminating Repetition Through Reusable Context

MemoryKnowledge prevents agents from "reinventing the wheel" by storing processed information as reusable assets. The [`/MemoryKnowledge/README.md`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main//MemoryKnowledge/README.md) states: *"Memory here means more than just 'remembering conversations.' Any information that helps the next Agent avoid reinventing the wheel should be saved, organized, and reused."* Instead of re-reading raw documents or re-executing previous analyses, agents load the needed asset on demand, significantly saving LLM context tokens and execution time.

### Cold-Start Enablement

The service is designed to be **cold-start friendly**. Existing project documentation, codebases, and conversation logs can be imported once, indexed asynchronously, and then made instantly available to any new agent. As implemented in [`src/engines/wiki/manager.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/engines/wiki/manager.ts) and [`src/engines/code/index.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/engines/code/index.ts), the ingestion pipeline processes raw files into searchable graphs and BM25 indexes, allowing agents to begin work immediately without waiting for real-time processing.

### Fine-Grained Access Control

Assets support four visibility levels: `private` (owner-only), `team` (visible to all team members), `restricted` (controlled via User/Role/Agent ACLs), and `agent` (specific to designated agents). As documented in [`/MemoryKnowledge/README.md`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main//MemoryKnowledge/README.md), this granularity lets administrators control exactly who can read or modify each piece of knowledge, ensuring sensitive code or documentation remains properly scoped.

## Technical Implementation and Code Structure

The MemoryKnowledge service is implemented across several key files in the `TencentCloud/TencentDB-Agent-Memory` repository:

- **[`src/store/wiki-service.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/store/wiki-service.ts)** – Implements CRUD operations and ingestion logic for Wiki assets, handling the asynchronous LLM processing that converts raw files into searchable pages.
- **[`src/store/code-graph-service.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/store/code-graph-service.ts)** – Manages repository cloning, symbol indexing, and call-graph construction for Code-Graph assets.
- **[`src/routes/wiki.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/routes/wiki.ts)** – Express router exposing REST endpoints for Wiki creation, ingestion, and search (`/v3/wiki/*`).
- **[`src/routes/code-graph.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/routes/code-graph.ts)** – Express router exposing Code-Graph endpoints including caller queries and impact analysis (`/v3/code-graph/*`).
- **[`src/engines/wiki/manager.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/engines/wiki/manager.ts)** – Core engine that parses raw documentation, runs LLM ingest pipelines, and builds the searchable Wiki graph.
- **[`src/engines/code/index.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/engines/code/index.ts)** – Code-Graph engine that normalizes symbols, builds call relationships, and powers impact path queries.

These components collectively deliver the **28 endpoints** defined in [`openapi.yaml`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/openapi.yaml), handling everything from asset creation to sophisticated code intelligence queries.

## Working with MemoryKnowledge: Practical Examples

The following examples demonstrate how to interact with MemoryKnowledge via its `/v3` API. All requests require the `x-tdai-service-id` header identifying your team tenant.

### Creating and Populating a Wiki

First, create a Wiki asset to store project documentation:

```bash
curl -X POST http://localhost:8421/v3/wiki/create \
  -H "Content-Type: application/json" \
  -H "x-tdai-service-id: <SERVICE_ID>" \
  -d '{
        "team_id": "<TEAM_ID>",
        "name": "Project-Docs"
      }'

```

This returns a `wiki_id` (e.g., `wiki-9c1f2b`). Next, trigger asynchronous ingestion of raw files:

```bash
curl -X POST http://localhost:8421/v3/wiki/ingest \
  -H "Content-Type: application/json" \
  -H "x-tdai-service-id: <SERVICE_ID>" \
  -d '{
        "wiki_id": "wiki-9c1f2b"
      }'

```

The [`src/engines/wiki/manager.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/engines/wiki/manager.ts) engine processes the files, generating searchable Wiki pages and BM25 indexes in the background.

### Querying Documentation

Search the indexed Wiki using the `/v3/wiki/search` endpoint:

```bash
curl -X POST http://localhost:8421/v3/wiki/search \
  -H "Content-Type: application/json" \
  -H "x-tdai-service-id: <SERVICE_ID>" \
  -d '{
        "wiki_id": "wiki-9c1f2b",
        "query": "authentication flow",
        "limit": 5
      }'

```

### Indexing and Analyzing Code

Create a Code-Graph asset to index a repository:

```bash
curl -X POST http://localhost:8421/v3/code-graph/create \
  -H "Content-Type: application/json" \
  -H "x-tdai-service-id: <SERVICE_ID>" \
  -d '{
        "team_id": "<TEAM_ID>",
        "repo_url": "https://github.com/example/repo.git",
        "branch": "main"
      }'

```

This returns a `code_graph_id` (e.g., `cg-7e3d10`). The background worker in [`src/store/code-graph-service.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/store/code-graph-service.ts) clones the repository and builds a call-graph index.

### Retrieving Call Relationships

Query which functions call a specific symbol for impact analysis:

```bash
curl -X POST http://localhost:8421/v3/code-graph/callers \
  -H "Content-Type: application/json" \
  -H "x-tdai-service-id: <SERVICE_ID>" \
  -d '{
        "code_graph_id": "cg-7e3d10",
        "symbol": "UserService.createUser",
        "limit": 10
      }'

```

The [`src/engines/code/index.ts`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/src/engines/code/index.ts) engine traverses the pre-built call graph to return the list of calling functions without requiring the LLM to parse source code in real-time.

## Summary

- **MemoryKnowledge** is the unified knowledge-service layer of TencentDB Agent Memory, providing 28 REST endpoints for managing Wiki and Code-Graph assets.
- Assets are **globally identified** (e.g., `wiki-`, `cg-` prefixes), versioned, and ACL-protected, enabling safe sharing across teams and agents.
- The architecture eliminates redundant work by allowing agents to **reuse processed knowledge** rather than re-reading raw documents or re-executing analyses.
- **Cold-start support** enables immediate agent productivity by importing and indexing existing documentation and codebases asynchronously.
- **Fine-grained access controls** (`private`, `team`, `restricted`, `agent`) ensure knowledge assets remain properly scoped to authorized users and agents.

## Frequently Asked Questions

### What types of assets does MemoryKnowledge manage?

MemoryKnowledge manages four primary asset types: **Wiki pages** (processed documentation with BM25 search), **Code-Graph indexes** (repository symbols, call graphs, and impact paths), **Chat Memory** (conversation histories), and **Skills** (reusable agent capabilities). Each asset type receives a globally unique ID and is stored with full version history and ACL metadata.

### How does MemoryKnowledge reduce LLM token consumption?

By storing **pre-processed, indexed assets** rather than raw source files, MemoryKnowledge allows agents to retrieve only the specific knowledge fragments required for the current task. Instead of stuffing entire codebases or documentation sets into the context window, agents call endpoints like `/v3/wiki/search` or `/v3/code-graph/callers` to get concise, relevant results, dramatically reducing token usage and improving response latency.

### What is the difference between Wiki and Code-Graph assets?

**Wiki assets** store and index unstructured documentation (Markdown, text, HTML) through an LLM ingestion pipeline that creates searchable pages and semantic indexes. **Code-Graph assets** store structured code intelligence: repository clones, symbol tables, call relationships, and impact paths built by parsing source code into queryable graphs. While Wiki assets answer "what" and "how" questions about processes, Code-Graph assets answer "where" and "who calls" questions about implementation.

### How does access control work in MemoryKnowledge?

Access control operates at the asset level through four visibility tiers defined in the [`openapi.yaml`](https://github.com/TencentCloud/TencentDB-Agent-Memory/blob/main/openapi.yaml) schema: `private` (restricted to the asset owner), `team` (visible to all members of the owning team), `restricted` (granted to specific Users, Roles, or Agents via ACLs), and `agent` (scoped to designated agents). Administrators create teams and agents in the Memory Hub, then review and share assets according to these policies, ensuring sensitive knowledge remains properly isolated.