Knowledge Documentation
Overview
Knowledge is the knowledge management system in the tRPC-Agent-Go framework, providing Retrieval-Augmented Generation (RAG) capabilities for Agents. By integrating vector data, embedding models, and document processing components, the Knowledge system helps Agents access and retrieve relevant knowledge information, providing more accurate and well-grounded responses.
Usage Pattern
The Knowledge system follows this usage pattern:
- Create Knowledge: Configure vector store, Embedder, and knowledge sources
- Load Documents: Load and index documents from various sources
- Create Search Tool: Use
NewKnowledgeSearchToolto create a knowledge search tool - Integrate with Agent: Add the search tool to the Agent's tool list
- Knowledge Base Management: Enable intelligent sync mechanism via
WithEnableSourceSync(true)to keep vector store data consistent with configured sources (see Knowledge Base Management)
This pattern provides:
- Intelligent Retrieval: Semantic search based on vector similarity
- Multi-source Support: Support for files, directories, URLs, and other knowledge sources
- Flexible Storage: Support for in-memory, PostgreSQL, TcVector, and other storage backends
- High-performance Processing: Concurrent processing and batch document loading
- Knowledge Filtering: Support for static filtering and Agent intelligent filtering via metadata
- Extensible Architecture: Support for custom Embedder, Retriever, and Reranker
Agent Integration
Ways to integrate the Knowledge system with Agents:
- Manual Tool Creation (Recommended): Use
NewKnowledgeSearchToolto create search tools with flexible tool names and descriptions, supporting multiple knowledge bases - Intelligent Filter Tool: Use
NewAgenticFilterSearchToolto create search tools with intelligent filtering - Auto Integration: Use
WithKnowledge()option to automatically addknowledge_searchtool (for simple scenarios) - Context Enhancement: Retrieved knowledge content is automatically added to the Agent's context
- Metadata Filtering: Support for precise search based on document metadata
Quick Start
Complete Example: examples/knowledge/basic
Requirements
- Valid LLM API key (OpenAI compatible interface)
- Vector database (optional, for production environments)
Environment Variables
Minimal Example
Core Concepts
The knowledge module is the knowledge management core of the tRPC-Agent-Go framework, providing complete RAG capabilities. The module uses a modular design, supporting various document sources, vector storage backends, and embedding models.
Agent Integration
The Knowledge system provides search tools to integrate knowledge base capabilities into Agents.
Search Tools
KnowledgeSearchTool
Basic search tool supporting semantic search and static filtering:
AgenticFilterSearchTool
Intelligent filter search tool, Agent can automatically build filter conditions based on user queries.
Supports multiple configuration methods such as automatic extraction, manually specifying enum values, and manually specifying fields:
Detailed configuration instructions please refer to Filter Documentation.
Search Tool Configuration Options
Both NewKnowledgeSearchTool and NewAgenticFilterSearchTool support the following configuration options:
| Option | Description | Default |
|---|---|---|
WithToolName(name) |
Set tool name | "knowledge_search" / "knowledge_search_with_agentic_filter" |
WithToolDescription(desc) |
Set tool description | Default description |
WithMaxResults(n) |
Set maximum number of documents to return | 10 |
WithMinScore(score) |
Set minimum relevance score threshold (0.0-1.0), documents below this score will be filtered | 0.0 |
WithFilter(map) |
Set static metadata filter (simple AND logic) | nil |
WithConditionedFilter(cond) |
Set complex filter conditions (supports AND/OR/nested logic) | nil |
Tip: Each returned document contains text content, metadata, and relevance score, sorted by score in descending order.
Integration Methods
Method 1: Manual Tool Addition (Recommended)
Use llmagent.WithTools to manually add search tools with flexible configuration and support for multiple knowledge bases:
Method 2: Automatic Integration
Use llmagent.WithKnowledge(kb) to integrate Knowledge into the Agent, and the framework will automatically register the knowledge_search tool.
Note: The automatic integration method is simple and quick, but less flexible. It doesn't allow customizing tool names, descriptions, filter conditions, or other parameters, and doesn't support integrating multiple knowledge bases simultaneously. For more fine-grained control, it's recommended to use the manual tool addition approach.
Performance Options at Loading
Knowledge supports batch document processing and concurrent loading, which can significantly improve performance when handling large amounts of documents:
About Performance and Rate Limiting:
- Increasing concurrency will increase the call frequency to Embedder services (OpenAI/Gemini), which may trigger rate limiting.
- Adjust
WithSourceConcurrency()andWithDocConcurrency()according to throughput, cost, and rate limits.- Default values are balanced for most scenarios; increase for speed if needed, decrease if rate limiting occurs.
Evaluation and Comparison
We have conducted comprehensive RAG quality evaluation of tRPC-Agent-Go, LangChain, Agno, and CrewAI using the RAGAS framework.
Detailed Documentation: For complete evaluation plan, parameter configuration, and result analysis, please refer to examples/knowledge/evaluation/README.md
Evaluation Plan
- Dataset: HuggingFace Documentation Dataset (m-ric/huggingface_doc)
- Metrics: 7 standard RAGAS metrics (Faithfulness, Answer Relevancy, Context Precision, etc.)
- Comparison: tRPC-Agent-Go vs LangChain vs Agno vs CrewAI with identical configuration parameters
Configuration Alignment
To ensure fair comparison, all four systems use identical configurations:
| Parameter | Configuration |
|---|---|
| System Prompt | Unified 5-rule constraint prompt |
| Temperature | 0 |
| Chunk Size | 500 |
| Chunk Overlap | 50 |
| Embedding Model | server:274214 (1024 dims) |
| Vector Store | PGVector (CrewAI uses ChromaDB) |
| Agent Model | DeepSeek-V3.2 |
More Content
- Vector Store - Configure various vector database backends
- Embedder - Text vectorization model configuration
- Reranker - Retrieval result reranking
- Document Sources - File, directory, URL, and other knowledge source configuration
- OCR Text Recognition - Configure Tesseract OCR for text extraction
- Filters - Basic filters and intelligent filters
- Knowledge Base Management - Dynamic source management and status monitoring
- Common Issues - Common issues and solutions