retriever_init
Signature
- Initializes retrieval service.
- Embedding Backend (backend): Responsible for converting text/images into vectors (Infinity, SentenceTransformers, OpenAI, BM25).
- Index Backend (index_backend): Responsible for vector storage and retrieval (FAISS, Milvus).
- Demo Mode: If is_demo=True, forces OpenAI + Milvus configuration, ignoring some parameters.
retriever_embed
Signature
- (Non-Demo Mode) Batches calculation of vector representations of corpus and saves as .npy file.
- Only applies to Dense Retriever backend (BM25 not supported).
retriever_index
Signature
- Builds retrieval index.
- FAISS: Reads embedding_path (.npy) to build local index file.
- Milvus / Demo: Reads corpus_path (.jsonl), generates vectors and inserts into specified collection_name.
retriever_search
Signature
- Retrieves single or multiple queries.
- Automatically handles query vectorization (adds query_instruction) and finds Top-K in specified collection_name (for Milvus) or default index.
retriever_batch_search
Signature
- Batch version of retriever_search, accepts nested list input.
bm25_index
Signature
- When
backend="bm25", builds BM25 sparse index and saves it.
bm25_search
Signature
- Keyword retrieval based on BM25 algorithm.
retriever_deploy_search
Signature
- As a client, calls remote retrieval service deployed at retriever_url for query.
retriever_exa_search
Signature
- Calls Exa Web retrieval (requires
EXA_API_KEY).
retriever_tavily_search
Signature
- Calls Tavily Web retrieval (requires
TAVILY_API_KEY).
retriever_zhipuai_search
Signature
- Calls ZhipuAI
web_search(requiresZHIPUAI_API_KEY).
Configuration
| Parameter | Type | Description |
|---|---|---|
model_name_or_path | str | Retrieval model path or name (e.g., HuggingFace model ID) |
corpus_path | str | Input corpus JSONL file path |
embedding_path | str | Vector file save path (.npy) |
collection_name | str | Milvus collection name |
backend | str | Select retrieval backend: infinity, sentence_transformers, openai, bm25 |
index_backend | str | Index backend: faiss, milvus |
backend_configs | dict | Parameter configuration for each backend (see table below) |
index_backend_configs | dict | Parameter configuration for each index backend (see table below) |
batch_size | int | Batch size for vector generation or retrieval |
top_k | int | Number of returned candidate passages |
gpu_ids | str | Specify visible GPU devices, e.g., "0,1" |
query_instruction | str | Query prefix (used by instruction-tuning models) |
is_multimodal | bool | Whether to enable multimodal embedding (e.g., image) |
overwrite | bool | Whether to overwrite if embedding or index file already exists |
retrieve_thread_num | int | Concurrent thread number for external Web retrieval (Exa/Tavily/Zhipu) |
retriever_url | str | URL of deployed retriever server |
is_demo | bool | Demo mode switch (forces OpenAI+Milvus, simplified configuration) |
backend_configs Sub-items:
| Backend | Parameter | Type | Description |
|---|---|---|---|
| infinity | bettertransformer | bool | Whether to enable efficient inference optimization |
pooling_method | str | Pooling method (e.g., auto, mean) | |
model_warmup | bool | Whether to preload model into VRAM | |
trust_remote_code | bool | Whether to trust remote code (Applicable to custom models) | |
| sentence_transformers | trust_remote_code | bool | Whether to trust remote model code |
sentence_transformers_encode | dict | Encoding detailed parameters, see table below | |
| openai | model_name | str | OpenAI model name (e.g., text-embedding-3-small) |
base_url | str | API base address | |
api_key | str | OpenAI API Key | |
| bm25 | lang | str | Language (determines stop words and tokenizer) |
save_path | str | Save directory for BM25 sparse index |
sentence_transformers_encode Parameters:
| Parameter | Type | Description |
|---|---|---|
normalize_embeddings | bool | Whether to normalize vectors |
encode_chunk_size | int | Encoding chunk size (avoid VRAM overflow) |
q_prompt_name | str | Query template name |
psg_prompt_name | str | Passage template name |
q_task | str | Task description (for cases where specific models need to specify Task) |
psg_task | str | Task description (for cases where specific models need to specify Task) |
index_backend_configs Parameters:
| Backend | Parameter | Type | Description |
|---|---|---|---|
| faiss | index_use_gpu | bool | Whether to use GPU for building and retrieving index |
| index_chunk_size | int | Batch size when building index | |
| index_path | str | Save path for FAISS index file (.index) | |
| milvus | uri | str | Milvus connection address (Local file path enables Milvus Lite) |
| token | str | Auth Token (if needed) | |
| id_field_name | str | Primary key field name (default id) | |
| vector_field_name | str | Vector field name (default vector) | |
| text_field_name | str | Text content field name (default contents) | |
| id_max_length | int | Maximum length of string primary key | |
| text_max_length | int | Maximum length of text field (truncated if exceeded) | |
| metric_type | str | Distance metric type (e.g., IP inner product, L2 Euclidean distance) | |
| index_params | Dict | Index construction parameters (e.g., index_type: AUTOINDEX) | |
| search_params | Dict | Retrieval parameters (e.g., nprobe etc.) | |
| index_chunk_size | int | Batch size when inserting data |