Project Overview
Langchain-Chatchat (formerly Langchain-ChatGLM) is an open-source, offline-deployable RAG and Agent application project, implemented based on large language models such as ChatGLM and application frameworks such as Langchain. The project aims to establish a knowledge base question-answering solution that is friendly to Chinese scenarios and open-source models and can run offline.
Main Capabilities
- Supports mainstream open-source LLMs, Embedding models, and vector databases on the market, enabling fully offline private deployment using only open-source models.
- Supports calling the OpenAI GPT API, and continuously expands access to various models and model APIs.
- The core functionality of version 0.3.x is implemented by the Agent, and users can also manually implement tool calls.
- Supports invoking services through the API provided based on FastAPI, or operating through a Streamlit-based WebUI.
- Implementation principle: load files -> read text -> split text -> vectorize text -> vectorize the question -> match the top k text vectors most similar to the question vector -> add the matched text as context together with the question to the prompt -> submit to the LLM to generate an answer.
- Starting from version 0.3.0, models are no longer loaded directly according to local model paths; instead, support is provided for integration with mainstream model inference frameworks, such as Xinference, Ollama, LocalAI, FastChat, One API, etc.
- Supports online API integration, including OpenAI ChatGPT, Azure OpenAI API, Anthropic Claude, Zhipu Qingyan, Baichuan, etc.
- Supports Python 3.8-3.11, has been tested on Windows, macOS, and Linux, and can be used under hardware conditions such as CPU, GPU, NPU, and MPS.
- Starting from version 0.3.1, local yaml files are used for configuration; after modification, the server updates automatically without restarting.
Usage
- Installation: Starting from version 0.3.0, a Python library installation method is provided, and it can be installed via pip; it can also be installed and deployed/developed from source, or deployed with Docker.
- Model inference framework: The model must first be started and loaded, for example Xinference, Ollama, etc.; it is recommended to place Langchain-Chatchat and the model deployment framework in different Python virtual environments to avoid dependency conflicts.
- Configuration: modify model_settings.yaml to configure models (such as DEFAULT_LLM_MODEL, DEFAULT_EMBEDDING_MODEL, etc.), modify basic_settings.yaml to configure the knowledge base path, and modify kb_settings.yaml to configure the knowledge base type (FAISS is used by default).
- Initialize the knowledge base and run the project.
- You can view knowledge base-related commands through chatchat kb --help.
Applicable Scenarios
- Local knowledge base question answering: build a knowledge base based on local documents and use an LLM for question answering.
- Offline private deployment: environments with data privacy requirements that hope to run fully offline using open-source models.
- Chinese scenarios: the project is friendly to Chinese scenarios and open-source models.
- Research and development: can serve as a development foundation for RAG and Agent applications.
Limitations and Notes
- This project does not involve fine-tuning or training processes, but fine-tuning or training can be used to optimize the results of this project.
- Because version 0.3.0 has been modified to support integration with different model deployment frameworks, users need to deploy the model inference framework and load the model themselves before use.
- The default listening address is 127.0.0.1. If access through the machine IP is needed, modify the listening address in basic_settings.yaml to 0.0.0.0.
- The structure of 0.3.x has changed greatly. When upgrading, it is recommended to redeploy according to the documentation and back up important data.
- The code of this project follows the Apache-2.0 license.