Compare commits

..

17 commits

Author SHA1 Message Date
c0e4013364 Merge pull request 'Switch to a multilingual embedding model for non-English queries' (#65) from feature/multilingual-embedding into main 2026-11-09 22:13:25 +01:00
2207b52d63 Merge pull request 'Mitigate prompt injection via user-message wrapping + explicit guard' (#64) from feature/prompt-injection-mitigation into main 2026-11-09 22:13:10 +01:00
d36955e2ad Merge pull request 'Streamlit UI polish: native theming, multi-chat sessions, follow-ups' (#63) from feature/streamlit-ui-polish into main 2026-11-09 22:12:45 +01:00
fdc3c24efe Switch to a multilingual embedding model for non-English queries
The embedding model (all-MiniLM-L6-v2) is English-only, so retrieval
quality degraded for questions asked in other languages even though the
chat model itself answers fine in them. Switched the default
EMBEDDING_MODEL to
sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 (50+
languages, same 384-dim output).

The vectorstore's on-disk cache was keyed only on the policy corpus
fingerprint, so changing the embedding model would have silently reused
a stale index built from the old model's (differently-meaning) vectors
instead of rebuilding. Folded EMBEDDING_MODEL into that fingerprint so a
model change now triggers a rebuild automatically.

Refs #16
2026-11-09 22:01:25 +01:00
d470563615 Merge pull request 'Document the Streamlit UI (agent trace, RAG sources, ticket highlighting)' (#62) from feature/document-streamlit-ui into main 2026-11-09 18:03:50 +01:00
fd9cfbabb3 Merge pull request 'Switch to qwen2.5:14b on GPU (RTX 5070 Ti), fix routing regression' (#61) from feature/switch-qwen-gpu into main 2026-11-08 22:21:55 +01:00
29a19db231 Merge pull request 'Fix prompt bugs found during live Ollama testing (llama3.2:3b)' (#60) from feature/fix-prompt-bugs into main 2026-11-08 15:57:36 +01:00
a9cda94a31 Merge pull request 'Initial README' (#59) from feature/initial-readme into main 2026-11-08 15:52:09 +01:00
533677efd5 Merge pull request 'Functional eval and load-test scripts' (#58) from feature/eval-load-test into main 2026-11-07 22:47:53 +01:00
5273a195c8 Merge pull request 'Containerize with Docker Compose' (#57) from feature/docker-compose into main 2026-11-07 16:38:16 +01:00
32281d04ac Merge pull request 'Streamlit chat UI' (#56) from feature/streamlit-chat-ui into main 2026-11-07 15:30:44 +01:00
e4a0d17cd2 Merge pull request 'Main agentic graph: intent classification and task routing' (#55) from feature/agentic-graph-routing into main 2026-11-06 16:34:20 +01:00
dec5156c7f Merge pull request 'Corrective RAG subgraph' (#54) from feature/corrective-rag-subgraph into main 2026-11-06 13:12:16 +01:00
e3b0143667 Merge pull request 'RAG ingestion pipeline and FAISS vectorstore' (#53) from feature/rag-ingestion-vectorstore into main 2026-11-06 10:13:40 +01:00
49a4d18280 Merge pull request 'Deterministic tools: PTO calculator and support ticketing' (#52) from feature/deterministic-tools into main 2026-11-05 23:07:52 +01:00
2163394e19 Merge pull request 'Agent scaffolding: config, state schema, tracing' (#51) from feature/agent-scaffolding into main 2026-11-05 22:14:14 +01:00
ca56593a84 Merge pull request 'Add synthetic internal policy corpus for the RAG knowledge base' (#50) from feature/rag-policy-corpus into main 2026-11-05 18:13:48 +01:00
3 changed files with 12 additions and 5 deletions

View file

@ -79,8 +79,9 @@ retrieve → grade_relevance ──relevant──→ generate_answer → (end)
└──not relevant & retries exhausted──→ generate_answer (confidence="low")
```
1. **`retrieve`** – FAISS similarity search (`k=4`) using the local `all-MiniLM-L6-v2`
embedding model.
1. **`retrieve`** – FAISS similarity search (`k=4`) using the local
`paraphrase-multilingual-MiniLM-L12-v2` embedding model (multilingual, so non-English
questions still retrieve reasonably against the English policy corpus).
2. **`grade_relevance`** – the LLM decides whether the retrieved snippets are sufficient.
3. **`rewrite_query`** – if not, the LLM rewrites the question (e.g. resolves pronouns like
"this"/"that", sharpens keywords), and returns to `retrieve` — at most 2 times.
@ -143,7 +144,7 @@ documents, and a "Rebuild index" button that clears the cached graph/store and f
| Component | Choice | Rationale |
|---|---|---|
| LLM | **Ollama runtime + `qwen2.5:14b`** (configurable via `OLLAMA_MODEL` env var) | No paid API; Ollama is just the local model server, so the actual model can be swapped via env var at any time, with no code change. The project originally started with `llama3.2:3b` (smaller, fast even on CPU), then switched to `qwen2.5:14b` once a GPU became available (RTX 5070 Ti, 16 GB VRAM) — see the `deploy.resources.reservations.devices` (NVIDIA GPU) block on the `ollama` service in `docker-compose.yml`. **The real functional eval and load test were run against both models** (see sections 5-6) — the GPU-backed Qwen gave not only better quality but also roughly a **4.3× latency improvement**. The trade-off that persisted across both models: smaller/mid-size LLMs are less reliable at strictly following a JSON format → so `app/llm.py` defensively parses the JSON response (extracts the first `{...}` block via regex, falls back to a sensible default on any missing/invalid field). |
| Embedding | **`sentence-transformers/all-MiniLM-L6-v2`** (local, runs on CPU) | Small (~90 MB), fast, no API key, good enough retrieval quality for a corpus of this size. |
| Embedding | **`sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2`** (local, runs on CPU) | Small (~470 MB), no API key, and multilingual (50+ languages) so retrieval still works reasonably when an employee asks in a language other than English, even though the policy corpus itself is English-only. The vectorstore cache key includes the embedding model name, so switching models (e.g. back to the smaller English-only `all-MiniLM-L6-v2`) auto-rebuilds the index instead of silently reusing incompatible vectors. |
| Vectorstore | **FAISS** (in-process, persisted to disk) | No separate infrastructure needed for a prototype; see the 2.4 scalability note. |
## 4. Installation and running

View file

@ -13,7 +13,9 @@ PROJECT_ROOT = Path(__file__).resolve().parent.parent
OLLAMA_MODEL = os.getenv("OLLAMA_MODEL", "qwen2.5:14b")
OLLAMA_BASE_URL = os.getenv("OLLAMA_BASE_URL", "http://localhost:11434")
EMBEDDING_MODEL = os.getenv("EMBEDDING_MODEL", "sentence-transformers/all-MiniLM-L6-v2")
EMBEDDING_MODEL = os.getenv(
"EMBEDDING_MODEL", "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
)
POLICY_DOCS_DIR = Path(os.getenv("POLICY_DOCS_DIR", PROJECT_ROOT / "app" / "data" / "policies"))
INDEX_DIR = Path(os.getenv("INDEX_DIR", PROJECT_ROOT / "app" / "data" / "index"))

View file

@ -46,11 +46,15 @@ def load_or_build_index(
"""Load a cached FAISS index from disk, rebuilding it if the corpus changed."""
from langchain_community.vectorstores import FAISS
from app.config import EMBEDDING_MODEL
docs_dir = Path(docs_dir)
index_dir = Path(index_dir)
embeddings = get_embeddings()
fingerprint_path = index_dir / _FINGERPRINT_FILE
current_fingerprint = corpus_fingerprint(docs_dir)
# Include the embedding model name so switching models invalidates the cache instead of
# silently loading vectors built by a different model (same FAISS dimension can mask this).
current_fingerprint = f"{corpus_fingerprint(docs_dir)}::{EMBEDDING_MODEL}"
index_is_fresh = (
not force_rebuild