How chatchat-space/langchain-chatchat works
LangChain-Chatchat is an offline-capable RAG, chat, and agent application exposed through FastAPI and a WebUI, with a Python SDK for clients. The principal workflow accepts a user question, routes it to chat handling, retrieves relevant knowledge when requested, and uses a configured language model to produce a response. Knowledge-base management and ingestion, file RAG, agents and tools, OpenAI-compatible model APIs, and persistent conversation/configuration state are distinct supporting capabilities. The README documents the retrieval stages; source-index references show route-to-handler and SDK relationships, but many internal calls were not sampled.
Main entry points: chat_routes.py Chat Routes · file_rag File RAG · chat.py Chat Handling · kb_chat.py Knowledge Chat
Components 22
User Interfaces
- HTTP API
libs/chatchat-server/chatchat/server/api_server/server_app.py - Chat Routes
libs/chatchat-server/chatchat/server/api_server/chat_routes.py - KB Routes
libs/chatchat-server/chatchat/server/api_server/kb_routes.py - OpenAI Routes
libs/chatchat-server/chatchat/server/api_server/openai_routes.py - WebUI
libs/chatchat-server/chatchat/webui.py - Python SDK
libs/python-sdk/open_chatcaht/api_client.py
Chat and Agents
- Chat Handling
libs/chatchat-server/chatchat/server/chat/chat.py - Knowledge Chat
libs/chatchat-server/chatchat/server/chat/kb_chat.py - File Chat
libs/chatchat-server/chatchat/server/chat/file_chat.py - Agent Runtime
libs/chatchat-server/langchain_chatchat/agents/all_tools_agent.py - Agent Tools
libs/chatchat-server/chatchat/server/agent/tools_factory/tools_registry.py
Knowledge Retrieval
- Knowledge Management
libs/chatchat-server/chatchat/server/knowledge_base/kb_doc_api.py - Knowledge Services
libs/chatchat-server/chatchat/server/knowledge_base/kb_service/base.py - File RAG
libs/chatchat-server/chatchat/server/file_rag - Vector Store
libs/chatchat-server/chatchat/server/knowledge_base/kb_service
Models and Tools
- Model API
libs/chatchat-server/chatchat/server/api_server/openai_routes.py - Embeddings
libs/chatchat-server/chatchat/server/localai_embeddings.py
Configuration and State
- Settings
libs/chatchat-server/chatchat/settings.py - Application Database
libs/chatchat-server/chatchat/server/db - API Schemas
libs/chatchat-server/chatchat/server/api_server/api_schemas.py
Other components
- User
- Model Provider
Connections 24
- User → HTTP API: submits request
README.md - User → WebUI: uses
README.md - HTTP API → Chat Routes: routes chat
- Chat Routes → Chat Handling: dispatches chat
libs/chatchat-server/chatchat/server/api_server/chat_routes.py - Chat Routes → Knowledge Chat: dispatches KB chat
libs/chatchat-server/chatchat/server/api_server/chat_routes.py - Chat Routes → File Chat: dispatches file chat
libs/chatchat-server/chatchat/server/api_server/chat_routes.py - KB Routes → Knowledge Management: manages documents
libs/chatchat-server/chatchat/server/api_server/kb_routes.py - Chat Handling → Agent Runtime: uses agent
- Agent Runtime → Agent Tools: invokes tools
- Knowledge Chat → File RAG: retrieves context
- File Chat → File RAG: processes files
- User → Knowledge Management: uploads documents
README.md - Knowledge Management → File RAG: loads and splits
README.md - File RAG → Embeddings: vectorizes text
README.md - Embeddings → Vector Store: indexes vectors
README.md - Knowledge Chat → Vector Store: searches vectors
README.md - Chat Handling → Model API: requests completion
- OpenAI Routes → Model Provider: forwards request
libs/chatchat-server/chatchat/server/api_server/openai_routes.py - Model API → Model Provider: calls model
- Python SDK → HTTP API: sends HTTP requests
- Chat Routes → API Schemas: uses request schemas
libs/chatchat-server/chatchat/server/api_server/chat_routes.py - OpenAI Routes → API Schemas: uses request schemas
libs/chatchat-server/chatchat/server/api_server/openai_routes.py - KB Routes → Application Database: accesses persistent state
- Settings → Vector Store: configures backends
libs/chatchat-server/chatchat/server/knowledge_base/kb_service/es_kb_service.py