Martechsol commited on
Commit ·
0487d4b
1
Parent(s): efff587
Fix latency: switch to bge-small and bge-reranker-base for CPU optimization
Browse files- PROJECT_OVERVIEW.md +2 -2
- app/core/config.py +2 -2
- app/services/llm.py +1 -1
PROJECT_OVERVIEW.md
CHANGED
|
@@ -11,9 +11,9 @@ The assistant uses a hybrid LLM approach:
|
|
| 11 |
## 2. How it Works (The "RAG" Process)
|
| 12 |
Instead of just relying on general knowledge, this bot "reads" your documents to give specific answers.
|
| 13 |
1. **Reading**: It looks at your files in the `docs/` folder (PDFs and Text files).
|
| 14 |
-
2. **Memorizing**: It breaks the text into small chunks and converts them into mathematical "vectors" (using the `bge-
|
| 15 |
3. **Searching**: When you ask a question, it expands the query using Llama 3.1 8B, then performs a **Hybrid Search** combining Dense vectors (**FAISS**) and Keyword search (**BM25**).
|
| 16 |
-
4. **Reranking**: It deeply evaluates the top retrieved chunks using `bge-reranker-
|
| 17 |
5. **Answering**: It sends your question along with the most relevant document parts to the Qwen 2.5 AI, which then writes a highly precise, formatted reply.
|
| 18 |
|
| 19 |
## 3. The Architecture
|
|
|
|
| 11 |
## 2. How it Works (The "RAG" Process)
|
| 12 |
Instead of just relying on general knowledge, this bot "reads" your documents to give specific answers.
|
| 13 |
1. **Reading**: It looks at your files in the `docs/` folder (PDFs and Text files).
|
| 14 |
+
2. **Memorizing**: It breaks the text into small chunks and converts them into mathematical "vectors" (using the `bge-small-en-v1.5` model).
|
| 15 |
3. **Searching**: When you ask a question, it expands the query using Llama 3.1 8B, then performs a **Hybrid Search** combining Dense vectors (**FAISS**) and Keyword search (**BM25**).
|
| 16 |
+
4. **Reranking**: It deeply evaluates the top retrieved chunks using `bge-reranker-base` to ensure maximum relevance.
|
| 17 |
5. **Answering**: It sends your question along with the most relevant document parts to the Qwen 2.5 AI, which then writes a highly precise, formatted reply.
|
| 18 |
|
| 19 |
## 3. The Architecture
|
app/core/config.py
CHANGED
|
@@ -14,8 +14,8 @@ class Settings(BaseSettings):
|
|
| 14 |
groq_rewrite_model: str = Field(default="llama-3.1-8b-instant", alias="GROQ_REWRITE_MODEL")
|
| 15 |
hf_api_key: str = Field(default="", alias="HF_API_KEY")
|
| 16 |
hf_model: str = Field(default="meta-llama/Llama-3.1-8B-Instruct", alias="HF_MODEL")
|
| 17 |
-
embedding_model: str = Field(default="BAAI/bge-
|
| 18 |
-
reranker_model: str = Field(default="BAAI/bge-reranker-
|
| 19 |
docs_dir: Path = Field(default=Path("docs"), alias="DOCS_DIR")
|
| 20 |
@model_validator(mode='after')
|
| 21 |
def set_persistent_paths(self) -> 'Settings':
|
|
|
|
| 14 |
groq_rewrite_model: str = Field(default="llama-3.1-8b-instant", alias="GROQ_REWRITE_MODEL")
|
| 15 |
hf_api_key: str = Field(default="", alias="HF_API_KEY")
|
| 16 |
hf_model: str = Field(default="meta-llama/Llama-3.1-8B-Instruct", alias="HF_MODEL")
|
| 17 |
+
embedding_model: str = Field(default="BAAI/bge-small-en-v1.5", alias="EMBEDDING_MODEL")
|
| 18 |
+
reranker_model: str = Field(default="BAAI/bge-reranker-base", alias="RERANKER_MODEL")
|
| 19 |
docs_dir: Path = Field(default=Path("docs"), alias="DOCS_DIR")
|
| 20 |
@model_validator(mode='after')
|
| 21 |
def set_persistent_paths(self) -> 'Settings':
|
app/services/llm.py
CHANGED
|
@@ -89,7 +89,7 @@ class LLMService:
|
|
| 89 |
# Ensure we include the original query too
|
| 90 |
if query not in queries:
|
| 91 |
queries.append(query)
|
| 92 |
-
return queries[:
|
| 93 |
except Exception:
|
| 94 |
return [query]
|
| 95 |
|
|
|
|
| 89 |
# Ensure we include the original query too
|
| 90 |
if query not in queries:
|
| 91 |
queries.append(query)
|
| 92 |
+
return queries[:3] # Original + 2 variations
|
| 93 |
except Exception:
|
| 94 |
return [query]
|
| 95 |
|