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

54 lines
2.2 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.
**SOLUTION.md**
**What was implemented**
- Switched from OpenAI embeddings/LLM to Ollamas `nomic-embed-text` for vector generation.
- Replaced the nonexistent `QdrantVectorStore` with a persistent ChromaDB store (`langchain.vectorstores.Chroma`).
- Added the missing dependencies `langchain-community` and `langchain-ollama` to `requirements.txt`.
- Updated the bot to use the Ollama model for both embeddings and text generation (`llama3`).
- Kept the interactive FAQ loop and retrievalQA chain intact.
**Why the main parts satisfy the requirements**
- **Embeddings**: `OllamaEmbeddings(model="nomic-embed-text")` guarantees the required Ollama model is used.
- **Vector store**: `Chroma` is imported from `langchain.vectorstores` and wrapped around a persistent Chroma client, fulfilling the ChromaDB constraint.
- **Dependencies**: `requirements.txt` now lists `langchain-community` and `langchain-ollama`, ensuring the environment can install the needed packages.
- **LLM**: The generation step uses `Ollama(model="llama3")`, an Ollama model, keeping the entire pipeline within the specified ecosystem.
**Key code excerpts**
*src/main.py embeddings and vector store*
```python
# 1. Set up embeddings using Ollama's "nomic-embed-text" model
embeddings = OllamaEmbeddings(model="nomic-embed-text")
```
```python
def create_vectorstore(embeddings, persist_directory: str = "chroma_db") -> Chroma:
...
vectorstore = Chroma(
client=client,
collection_name="faq",
embedding_function=embeddings
)
return vectorstore
```
*src/main.py retrievalQA chain*
```python
qa_chain = RetrievalQA.from_chain_type(
llm=llm,
chain_type="stuff",
retriever=vectorstore.as_retriever()
)
```
*requirements.txt* (excerpt)
```
langchain-community
langchain-ollama
```
**Limitations**
- The bot currently uses a hardcoded FAQ list; adding dynamic data sources would require further changes.
- Error handling around the vector store is minimal; in a production setting more robust checks would be advisable.
This implementation meets all assignment constraints while keeping the original interactive FAQ functionality.