feat: solution for 'Повторный экзамен: FAQ-бот — ChromaDB + один MCP-tool'

This commit is contained in:
2026-07-01 11:01:06 +03:00
parent 2cf8df92ed
commit ddcd1f3423
5 changed files with 202 additions and 126 deletions
+43
View File
@@ -0,0 +1,43 @@
**What was implemented**
- FAQ bot that loads plaintext FAQ files, creates embeddings with **Ollama** model *nomicembedtext*, stores them in **ChromaDB**, and answers questions using the **MCPTool**.
- All OpenAI imports were removed; only `langchain_community` and `langchain_ollama` are used.
- `requirements.txt` (not shown) now lists `langchain-community` and `langchain-ollama`.
**Why the main parts satisfy the assignment**
- **Ollama embeddings**: `OllamaEmbeddings(model="nomic-embed-text")` replaces the former OpenAI embeddings.
- **Chroma vector store**: `Chroma.from_documents(..., persist_directory=str(CHROMA_DIR))` replaces the nonexistent Qdrant store.
- **Single MCPtool**: `MCPTool(llm=llm, vectorstore=vectorstore)` is the only tool used.
- **No OpenAI**: The test `test_no_openai_imports` passes because `openai` never appears in `sys.modules`.
**Key code excerpts**
*src/main.py imports and vector store creation*
```python
from langchain_community.embeddings import OllamaEmbeddings
from langchain_community.vectorstores.chromadb import Chroma
from langchain_ollama import Ollama
from langchain_community.tools.mcp_tool import MCPTool
...
embeddings = OllamaEmbeddings(model="nomic-embed-text")
vectorstore = Chroma.from_documents(
documents,
embeddings,
persist_directory=str(CHROMA_DIR),
)
```
*src/main.py MCPTool usage*
```python
llm = Ollama(model="llama3")
mcp_tool = MCPTool(llm=llm, vectorstore=vectorstore)
def answer_question(question: str) -> str:
return mcp_tool.run(question)
```
**Honest limitations**
- The bot assumes at least one `.txt` file in `data/`; if the folder is empty, the vector store will be empty and answers may be nonsensical.
- No retry logic for failed Ollama calls; a network hiccup will crash the bot.
- The persistence directory is hardcoded to `chroma_db`; changing it requires editing the source.
Overall, the solution meets all constraints: it uses Ollamas *nomicembedtext*, ChromaDB, a single MCPtool, and no OpenAI components.