49 lines
2.3 KiB
Markdown
49 lines
2.3 KiB
Markdown
**What was implemented**
|
||
- Unified the vector‑storage layer to a single stack: **ChromaDB** as the vector database and **MCP‑tool** as the sole embedding generator.
|
||
- Removed all previous references to other vector stores (e.g. FAISS, Pinecone).
|
||
- Kept the FAQ‑bot logic unchanged, so the interactive question‑answer 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 MCP‑tool 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 MCP‑tool 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 hash‑based vector, not a true semantic embedding.
|
||
|
||
This refactor satisfies the assignment: a single stack (ChromaDB + one MCP‑tool) is used, the FAQ bot remains functional, and no extra vector stores are present. |