跪拜 Guibai
← All articles
Frontend · Backend · AI Programming

A TypeScript RAG Stack That Turns Project Decisions Into a Queryable Asset

By 颜进强 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Most RAG tutorials stop at a demo that stuffs PDFs into a vector store and calls it done. CorpRAG models the harder, higher-value problem: maintaining a living index of project rationale that an AI agent can query through a standard protocol, with every answer pointing back to a specific source file.

Summary

Project context — why JWT was chosen over sessions, why a table was split, what constraint a business rule addressed — decays faster than code. CorpRAG captures these decisions as structured Markdown documents and runs them through a full RAG pipeline: chunking, embedding with nomic-embed-text via Ollama, and similarity search in LanceDB. The system separates knowledge by business domain and tags each chunk with metadata for filtering and source traceability.

Instead of bolting a chatbot directly onto the retrieval layer, the project exposes query tools through the Model Context Protocol. An MCP-capable AI client can call domain-specific tools like ext_query or fr_query on demand, keeping context windows small and answers grounded in specific source documents. The architecture decouples retrieval from generation, so the knowledge base can be re-indexed without touching client prompts.

The column that accompanies the code treats RAG as a data pipeline to debug, not a magic API. It walks through each link — document loading, splitting, embedding, vector storage, and MCP tool wrapping — and stresses that answer quality is the product of every stage multiplied together.

Takeaways
Project knowledge is organized by business system (EXT, FR, GA) and split into Business Decision Records (BADR) and Technical Decision Records (FADR) in Markdown.
Documents are chunked (default 500 characters with 50-character overlap), embedded with nomic-embed-text via Ollama, and stored in LanceDB with metadata for system, document type, and source path.
Querying filters by system and optionally by document type; when no type is specified, both BADR and FADR tables are searched and results are merged.
CorpRAG exposes domain-specific tools (ext_query, fr_query, ga_query, rebuild_kb) through MCP so AI clients retrieve only the most relevant chunks on demand.
Answer quality is the product of document quality, chunk quality, embedding model, retrieval strategy, prompt constraints, and LLM capability — a failure in any link degrades the output.
Index and query must use the same embedding model; switching models requires a full index rebuild because vector dimensions and semantic spaces differ.
Conclusions

Treating RAG as a composable pipeline rather than a monolithic API call forces developers to isolate failures: a bad answer could be a chunking problem, a retrieval problem, or a prompt problem, and each has a different fix.

Exposing retrieval through MCP tools instead of a direct chat loop is an underappreciated architectural choice. It lets the knowledge base evolve independently of whichever LLM client eventually consumes it, and it avoids the context-window bloat that comes from dumping entire document sets into a system prompt.

The default chunk size of 500 with 50 overlap is presented as a starting point to validate against real queries, not a tuned recommendation. Most RAG projects skip this empirical tuning step and then blame the model for poor retrieval.

Concepts & terms
RAG (Retrieval-Augmented Generation)
A pattern where a user query first retrieves relevant documents from a knowledge base, then passes both the query and the retrieved context to a large language model to generate a grounded answer.
MCP (Model Context Protocol)
An open protocol that standardizes how AI clients discover and invoke tools, resources, and prompts. In CorpRAG, it decouples the retrieval layer from the generation layer so any MCP-compatible client can query the knowledge base.
LanceDB
An embedded vector database that runs directly from a local directory without a separate server process, making it suitable for personal projects and local-first RAG experiments.
nomic-embed-text
An embedding model runnable via Ollama that converts text into fixed-length vectors for semantic similarity search.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗