Memory Knowledge Service: Architecture and Management Capabilities in TencentDB Agent Memory

The Memory Knowledge Service (KS) is an independent HTTP service in the TencentDB-Agent-Memory monorepo that manages user-side Wiki capabilities and Code-Graph indexing, exposing LLM-powered document ingestion, full-text search, and symbol-level code exploration through a Hono-based REST API on port 8421.

The Memory Knowledge Service serves as the central knowledge backend for the TencentDB-Agent-Memory ecosystem. It stores, indexes, and serves both unstructured documents and source code repositories, enabling AI agents to retrieve contextual information via structured HTTP endpoints. Built on the Hono web framework, this component orchestrates SQLite-backed full-text search, knowledge graph construction, and automated synchronization pipelines.

Core Capabilities and Managed Resources

The service manages three primary asset types: unstructured documents through LLM-Wiki, source code repositories through Code-Graph, and executable tooling for agent consumption.

LLM-Wiki Document Management

The LLM-Wiki capability handles the complete lifecycle of user-uploaded documents. When content is submitted via POST /v3/wiki/raw/write, the service accepts batches of up to 10 files (each ≤ 512 KB) and stores them temporarily. The POST /v3/wiki/ingest endpoint then triggers an LLM extraction pipeline that:

  • Parses document content into structured pages
  • Builds a navigable knowledge graph from page relationships
  • Indexes content in an SQLite-backed FTS5 (Full-Text Search) database for semantic retrieval

The wiki implementation resides in MemoryKnowledge/src/routes/wiki.ts, which defines 15 distinct endpoints including /wiki/create, /wiki/search, and graph exploration views.

Code-Graph Repository Indexing

The Code-Graph subsystem manages symbol-level indexing of Git repositories. Implemented in MemoryKnowledge/src/routes/code-graph.ts, this capability clones repositories using the Git fetcher defined in MemoryKnowledge/src/source-fetcher/git-fetcher.ts, then constructs a traversable index of:

  • Function and class definitions
  • Cross-reference call graphs
  • File tree hierarchies

This enables agents to query code structure without parsing raw source files repeatedly.

Automated Synchronization and Tooling

The Auto-Sync feature (optional) periodically scans the Code-Graph queue in MemoryKnowledge/src/routes/auto-sync.ts, pulls updates from Git remotes, and rebuilds indexes automatically. Additionally, the Tools API exposes POST /v3/tools/list and POST /v3/tools/call endpoints defined in MemoryKnowledge/src/routes/tools.ts, allowing agents to discover and invoke built-in utilities programmatically.

Architecture and Route Organization

The service entry point in MemoryKnowledge/src/server.ts initializes the HTTP server on default port 8421 and mounts all route groups under the /v3 API prefix. The initialization sequence performs four critical steps:

  1. Loads environment configuration
  2. Creates the SQLite database connection via MemoryKnowledge/src/store/sqlite-store.ts
  3. Initializes the knowledge module, wiring together the wiki engine, code-graph engine, job queues, and telemetry
  4. Conditionally serves Swagger UI documentation

Route groups are organized by functional domain:

Data Storage and Indexing Strategy

All persistent state resides in SQLite, accessed through a Drizzle ORM layer defined in MemoryKnowledge/src/store/sqlite-store.ts. The database schema supports:

  • Wiki metadata and document versioning
  • FTS5 virtual tables for high-performance full-text search
  • Knowledge graph edge storage for relationship traversal

This storage architecture ensures zero external dependency requirements for basic operation while maintaining ACID guarantees for concurrent document ingestion and search operations.

API Endpoints and Practical Usage

The service exposes a comprehensive REST API for programmatic interaction. All endpoints require the x-tdai-service-id header for tenant isolation.

Verify service health:

curl -s http://127.0.0.1:8421/health

Initialize a new knowledge base:

curl -X POST http://127.0.0.1:8421/v3/wiki/create \
  -H "x-tdai-service-id: svc-123" \
  -d '{"team_id":"team-abc","name":"MyWiki"}' \
  -H "Content-Type: application/json"

Upload raw documents for processing:

curl -X POST http://127.0.0.1:8421/v3/wiki/raw/write \
  -H "x-tdai-service-id: svc-123" \
  -d '{
        "team_id":"team-abc",
        "wiki_id":"wiki-001",
        "files":[
          {"filename":"README.md","content":"# Hello"},

          {"filename":"doc.txt","content":"Sample text"}
        ]
      }' \
  -H "Content-Type: application/json"

Trigger LLM-based extraction and indexing:

curl -X POST http://127.0.0.1:8421/v3/wiki/ingest \
  -H "x-tdai-service-id: svc-123" \
  -d '{"wiki_id":"wiki-001","user_id":"user-42"}' \
  -H "Content-Type: application/json"

Execute semantic search with graph traversal parameters:

curl -X POST http://127.0.0.1:8421/v3/wiki/search \
  -H "x-tdai-service-id: svc-123" \
  -d '{"wiki_id":"wiki-001","query":"authentication","limit":5,"hop":2,"decay":0.7}' \
  -H "Content-Type: application/json"

Discover available agent tools:

curl -X POST http://127.0.0.1:8421/v3/tools/list \
  -H "x-tdai-service-id: svc-123" \
  -d '{"wiki_id":"wiki-001"}' \
  -H "Content-Type: application/json"

Integration and Telemetry

After ingestion or synchronization completes, the Memory Knowledge Service notifies the Panel service via the TMC_CALLBACK_URL environment variable, enabling remote metadata synchronization. The service also supports optional telemetry streaming:

  • Tool-call logs stream to ClickHouse when configured
  • LLM execution traces export to Langfuse for observability

Both telemetry channels are gated by environment variables and initialized during the server boot sequence in MemoryKnowledge/src/server.ts.

Summary

  • The Memory Knowledge Service is a Hono-based HTTP service defaulting to port 8421 that manages both document wikis and code repositories.
  • It provides LLM-Wiki capabilities for document ingestion and Code-Graph functionality for source code indexing, both backed by SQLite with FTS5 full-text search.
  • Route handlers are organized in MemoryKnowledge/src/routes/ with wiki, code-graph, tools, and auto-sync modules mounted under the /v3 prefix.
  • The service exposes 15+ Wiki endpoints including raw file upload, LLM extraction, and graph-aware search with configurable hop and decay parameters.
  • Integration features include status callbacks to the Panel service and optional ClickHouse/Langfuse telemetry for production observability.

Frequently Asked Questions

What port and API prefix does the Memory Knowledge Service use?

The service listens on port 8421 by default and mounts all API routes under the /v3 prefix. The entry point in MemoryKnowledge/src/server.ts configures this routing structure during initialization.

How does the service handle document search and retrieval?

Documents are indexed using SQLite FTS5 (Full-Text Search) virtual tables via the storage layer in MemoryKnowledge/src/store/sqlite-store.ts. The POST /v3/wiki/search endpoint supports semantic queries with graph traversal options including hop (relationship depth), decay (relevance weighting), and minScore filtering.

What is the difference between Wiki routes and Code-Graph routes?

Wiki routes in MemoryKnowledge/src/routes/wiki.ts manage unstructured documents through upload, LLM extraction, and text search workflows. Code-Graph routes in MemoryKnowledge/src/routes/code-graph.ts handle Git repository cloning and symbol-level graph queries, enabling agents to explore code structure and call relationships.

How does the service integrate with external observability tools?

When environment variables are configured, the service streams tool-call logs to ClickHouse and LLM traces to Langfuse during request processing. Additionally, completion callbacks to the Panel service via TMC_CALLBACK_URL ensure metadata consistency across the TencentDB-Agent-Memory platform.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →