Files
povtornyy-ekzamen-faq-bot-c…/SOLUTION.md
T

49 lines
2.3 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
**What was implemented**
- Unified the vectorstorage layer to a single stack: **ChromaDB** as the vector database and **MCPtool** as the sole embedding generator.
- Removed all previous references to other vector stores (e.g. FAISS, Pinecone).
- Kept the FAQbot logic unchanged, so the interactive questionanswer loop still works.
**Why the main parts satisfy the requirements**
- `VectorStore` now only talks to a ChromaDB collection (`chromadb.Client`) and uses `mcp_tool.get_embedding` for every document and query.
- The MCPtool implements a deterministic fallback embedding, so the bot can run even without an OpenAI key, while still allowing real embeddings when the key is present.
- The bot loads documents once, stores them in the single ChromaDB collection, and queries that same collection no other vector store is involved.
**Key code excerpts**
*src/vector_store.py* single ChromaDB collection and MCPtool usage
```python
self.client = chromadb.Client(Settings())
self.collection = self.client.get_or_create_collection(name=collection_name)
...
embeddings.append(get_embedding(doc["text"]))
...
embedding = get_embedding(query_text)
results = self.collection.query(query_embeddings=[embedding], n_results=top_k)
```
*src/mcp_tool.py* one embedding generator with OpenAI fallback
```python
def get_embedding(text: str) -> List[float]:
api_key = os.getenv("OPENAI_API_KEY")
if api_key and openai:
...
return response["data"][0]["embedding"]
return _hash_embedding(text)
```
*src/faq_bot.py* uses the unified `VectorStore`
```python
store = VectorStore()
if store.collection.count() == 0:
docs = load_documents(data_dir)
store.add_documents(docs)
...
results = store.query(query, top_k=3)
```
**Honest limitations**
- The deterministic dummy embedding may reduce retrieval quality when no OpenAI key is set.
- ChromaDB is embedded in memory by default; persistence depends on the local ChromaDB configuration.
- No additional vector store is introduced, but the fallback embedding is a simple hashbased vector, not a true semantic embedding.
This refactor satisfies the assignment: a single stack (ChromaDB + one MCPtool) is used, the FAQ bot remains functional, and no extra vector stores are present.