How lrj021029/ai-knowledge-base works
This is a FastAPI-backed RAG knowledge base. Users upload documents for parsing, enrichment, chunking, embedding, and indexing, then submit questions for retrieval, ranking, and answer generation; query history is also managed. The README additionally describes MCP web search and book recommendation/detail capabilities. Graph edges follow explicit README statements or source-index references and shown calls; unsampled wiring is omitted rather than inferred.
Main entry points: agent/main_graph.py Query Workflow · agent/main_graph.py Import Workflow · providers.py LLM Provider · query_server.py Query API
Components 32
HTTP API
- Import API
app/api/http/import_server.py - Query API
app/api/http/query_server.py
Document Import
- Import Workflow
app/process/import_/agent/main_graph.py - Import State
app/process/import_/agent/state.py - PDF Parsing
app/rag/import_/pdf_parse_service.py - Markdown Images
app/process/import_/agent/nodes/node_md_img.py - Document Splitting
app/rag/import_/split_service.py - Item Recognition
app/rag/import_/item_name_service.py - Chunk Embeddings
app/rag/import_/embedding_service.py - Vector Indexing
app/rag/import_/index_service.py
Question Answering
- Query Workflow
app/process/query/agent/main_graph.py - Query State
app/process/query/agent/state.py - Hybrid Search
app/rag/query/embedding_search_service.py - HyDE Search
app/rag/query/hyde_search_service.py - MCP Web Search
app/rag/query/web_search_service.py - Item Confirmation
app/rag/query/item_name_confirm_service.py - RRF Fusion
app/rag/query/rrf_service.py - Reranking
app/rag/query/rerank_service.py - Answer Generation
app/rag/query/answer_service.py - Book Discovery
app/api/http/query_server.py
Models and Storage
- LLM Provider
app/infra/llm/providers.py - Milvus Gateway
app/infra/vectorstore/milvus_gateway.py - MinIO Gateway
app/infra/object_storage/minio_gateway.py - History Repository
app/infra/persistence/history_repository.py - Mongo History Client
app/shared/clients/mongo_history_utils.py - Infrastructure Config
app/infra/config/providers.py
Shared Runtime
- Task Tracking
app/shared/utils/task_utils.py - SSE Utilities
app/shared/utils/sse_utils.py - Shared Configuration
app/shared/config/common.py - Prompt Loader
app/shared/runtime/load_prompt.py
Other components
- User
- Web Search Service
Connections 42
- User → Import API: uploads files
- Import API → Import Workflow: starts import
app/api/http/import_server.py - Import Workflow → PDF Parsing: parses PDFs
app/process/import_/agent/main_graph.py - Import Workflow → Markdown Images: processes images
app/process/import_/agent/main_graph.py - Import Workflow → Document Splitting: splits documents
app/process/import_/agent/main_graph.py - Import Workflow → Item Recognition: recognizes names
app/process/import_/agent/main_graph.py - Import Workflow → Chunk Embeddings: embeds chunks
app/process/import_/agent/main_graph.py - Import Workflow → Vector Indexing: indexes chunks
app/process/import_/agent/main_graph.py - Chunk Embeddings → LLM Provider: creates embeddings
app/rag/import_/embedding_service.py - Hybrid Search → LLM Provider: embeds query
app/rag/query/embedding_search_service.py - Hybrid Search → Milvus Gateway: hybrid searches
app/rag/query/embedding_search_service.py - HyDE Search → LLM Provider: generates HyDE
app/rag/query/hyde_search_service.py - HyDE Search → Milvus Gateway: hybrid searches
app/rag/query/hyde_search_service.py - HyDE Search → Prompt Loader: loads prompt
app/rag/query/hyde_search_service.py - Item Recognition → LLM Provider: uses LLM
app/rag/import_/item_name_service.py - Item Recognition → Milvus Gateway: checks names
app/rag/import_/item_name_service.py - User → Query API: asks question
- Query API → Query Workflow: runs query
app/api/http/query_server.py - Query Workflow → Hybrid Search: dispatches search
app/process/query/agent/main_graph.py - Query Workflow → HyDE Search: dispatches HyDE
app/process/query/agent/main_graph.py - Query Workflow → MCP Web Search: dispatches web search
app/process/query/agent/main_graph.py - Query Workflow → Item Confirmation: dispatches confirmation
app/process/query/agent/main_graph.py - Query Workflow → RRF Fusion: dispatches fusion
app/process/query/agent/main_graph.py - Query Workflow → Reranking: dispatches reranking
app/process/query/agent/main_graph.py - Query Workflow → Answer Generation: dispatches answer
app/process/query/agent/main_graph.py - MCP Web Search → Web Search Service: searches web
- Answer Generation → LLM Provider: generates response
app/rag/query/answer_service.py - Answer Generation → History Repository: stores messages
app/rag/query/answer_service.py - Query API → History Repository: reads history
app/api/http/query_server.py - History Repository → Mongo History Client: delegates persistence
app/infra/persistence/history_repository.py - Query API → Task Tracking: tracks tasks
app/api/http/query_server.py - Task Tracking → SSE Utilities: pushes progress
app/shared/utils/task_utils.py - Import API → Task Tracking: tracks imports
app/api/http/import_server.py - Query API → SSE Utilities: streams events
app/api/http/query_server.py - LLM Provider → Infrastructure Config: reads settings
app/infra/llm/providers.py - Milvus Gateway → Infrastructure Config: reads settings
app/infra/vectorstore/milvus_gateway.py - Chunk Embeddings → Import State: updates state
app/rag/import_/embedding_service.py - Hybrid Search → Query State: reads state
app/rag/query/embedding_search_service.py - HyDE Search → Query State: reads state
app/rag/query/hyde_search_service.py - Infrastructure Config → Shared Configuration: assembles settings
app/infra/config/providers.py - User → Book Discovery: requests discovery
- Book Discovery → Query Workflow: book query flow
app/api/http/query_server.py