RAG & Embedding Configuration#
The RAG pipeline in Cyber Huatuo uses a local embedding model downloaded from ModelScope to vectorize documents for retrieval. All embedding settings are centralized in config/config-web.yaml under the model.embedding key, and loaded at runtime via the Config singleton.
Config File: model.embedding Keys#
Defined in config/config-web.yaml:
| Key | Default Value | Description |
|---|---|---|
model-path | C:/Users/<username>/.cache/modelscope/hub/ | Local cache directory where ModelScope downloads the embedding model |
model-name | iic/nlp_corom_sentence-embedding_chinese-base | ModelScope model ID (Chinese sentence embedding) |
model-version | v1.1.0 | Declared version — currently unused by runtime code |
device | cpu | Target device — currently unused by runtime code |
Note: Only
model-pathandmodel-nameare read by the Python runtime. Themodel-versionanddevicekeys are declared in the YAML but not consumed by any code.
The knowledge base document directory is also set in the same file :
Knowledge-base-path: ./konwledge-base
How Configuration is Loaded#
Config is a thread-safe singleton. It selects the YAML file by reading the PY_ENVIRONMENT environment variable and opening config/config-{env}.yaml . For web deployments, this resolves to config-web.yaml. Nested values are accessed via get_with_nested_params(), which is memoized with @lru_cache.
To switch environments, set PY_ENVIRONMENT before launch (e.g., PY_ENVIRONMENT=web).
Where Embedding Config is Consumed#
Two model classes read from model.embedding:
1. model/RAG/retrieve_model.py — Local Knowledge Base RAG
Retrievemodel.__init__ reads both model-path and model-name, joins them to form the full local model path , and auto-downloads the model via snapshot_download if it is not already present on disk . It then initializes ModelScopeEmbeddings with the resolved path and builds a FAISS vector store from the local knowledge base files.
2. model/Internet/Internet_model.py — Internet Search RAG
InternetModel.__init__ reads only model-name (not model-path) and passes it directly as the model_id to ModelScopeEmbeddings . This means internet-search RAG relies on ModelScope's default resolution rather than the explicit local cache path.
RAG Pipeline Architecture#
rag/rag_chain.py
└─> rag/retrieve/retrieve_document.py
└─> model/RAG/retrieve_service.py
└─> model/RAG/retrieve_model.py ← embedding config applied here
The local knowledge base retriever supports PDF, DOCX, TXT, HTML, MHTML, CSV, JSON, and Markdown files loaded from the Knowledge-base-path directory . Documents are chunked with RecursiveCharacterTextSplitter and indexed into FAISS.
Changing the Embedding Model#
To swap the embedding model:
- Update
model-nameinconfig/config-web.yamlto any valid ModelScope model ID. - Update
model-pathif you want to control the download cache location . - The model is downloaded automatically on first run if the path does not exist .
- Note that
InternetModelignoresmodel-path— it uses onlymodel-namefor resolution .