How zhanghang2017/ai-chat-rag works
AI-CHAT-RAG is a local knowledge-base RAG application: users upload and manage files, which are indexed into a vector store, then ask questions answered with retrieved context. The graph separates the React client, Node business service and Python AI service, showing documented ingestion callbacks and chat streaming. README documents the major workflows; sampled source confirms selected ingestion, callback and chat entry points, so some internal wiring is shown only where supported.
Main entry points: file.service.ts File operations · ingestion_service.py Document ingestion · chat.controller.ts Chat API · file.controller.ts File API
Components 30
React client
- App and pages
client/src/App.tsx - Knowledge-base actions
client/src/hooks/useKnowledgeBasePage.ts - Upload workflow
client/src/workservice/uploadWorkservice.ts - Ingestion events
client/src/components/knowledge-base/IngestionEventProvider.tsx - Chat interface
client/src/routes/ChatPage.tsx - Chat client
client/src/workservice/chatWorkservice.ts
Node business service
- File API
backend-server/src/controllers/file.controller.ts - File operations
backend-server/src/services/file.service.ts - Ingestion scheduling
backend-server/src/services/ingestionScheduler.ts - Ingestion events
backend-server/src/services/ingestionEvents.ts - File records
backend-server/src/repositories/file.repository.ts - Task records
backend-server/src/repositories/task.repository.ts - Chat API
backend-server/src/controllers/chat.controller.ts - Chat sessions
backend-server/src/services/chat.service.ts - Chat records
backend-server/src/repositories/chat.repository.ts - AI service proxy
backend-server/src/services/ai.service.ts
Python AI service
- AI API
AI-server/main.py - Document ingestion
AI-server/app/knowledge_base/ingestion_service.py - Document parsing
AI-server/app/knowledge_base/document_loader.py - Embedding model
AI-server/app/knowledge_base/embedding_model.py - Vector store access
AI-server/app/knowledge_base/vector_store.py - Ingestion callbacks
AI-server/app/knowledge_base/ingestion_callback_client.py - RAG chat
AI-server/app/chat/service.py - Knowledge retrieval
AI-server/app/chat/retriever.py - Chat model
AI-server/app/chat/llm.py
State and AI integrations
- Application database
backend-server/src/lib/prisma.ts - Chroma vector store
- Embedding provider
- Chat model provider
Other components
- User
Connections 37
- User → App and pages: uses
- App and pages → Knowledge-base actions: opens knowledge base
- Knowledge-base actions → Upload workflow: uploads and manages
- Upload workflow → File API: sends file requests
- File API → File operations: delegates
- File operations → File records: reads and writes
- File operations → Task records: reads and writes
- File operations → Ingestion scheduling: schedules tasks
- File operations → AI API: dispatches ingestion
- AI API → Document ingestion: queues background job
- Document ingestion → Document parsing: parses documents
- Document ingestion → Embedding model: vectorizes chunks
- Embedding model → Embedding provider: requests embeddings
- Document ingestion → Vector store access: writes chunks
- Vector store access → Chroma vector store: reads and writes vectors
- Document ingestion → Ingestion callbacks: reports progress and chunks
- Ingestion callbacks → File API: posts callbacks
- File API → File operations: handles callback data
- File operations → Ingestion events: publishes status events
- Ingestion events → Ingestion events: receives event stream
- Knowledge-base actions → Ingestion events: refreshes on updates
- App and pages → Chat interface: opens chat
- Chat interface → Chat client: submits questions
- Chat client → Chat API: sends chat requests
- Chat API → Chat sessions: manages sessions and messages
- Chat sessions → Chat records: reads and writes
- Chat API → AI service proxy: requests streamed answer
- AI service proxy → AI API: forwards chat request
- AI API → RAG chat: starts stream
- RAG chat → Knowledge retrieval: retrieves context
- Knowledge retrieval → Vector store access: searches vectors
- RAG chat → Chat model: generates response
- Chat model → Chat model provider: requests completion
- Chat API → Chat client: streams answer events
- File records → Application database: persists file metadata
- Task records → Application database: persists task state
- Chat records → Application database: persists chat history