100 lines
3.9 KiB
Markdown
100 lines
3.9 KiB
Markdown
**What was implemented**
|
||
- Replaced the previous Qdrant/OpenAI stack with **ChromaDB** for vector storage and **Ollama** for embeddings and LLM.
|
||
- Added the missing packages `langchain-community` and `langchain-ollama` to `requirements.txt`.
|
||
- Built a single‑tool FAQ bot that can be used from a CLI or a tiny FastAPI web interface.
|
||
- The bot uses a Retrieval‑QA chain powered by the Chroma collection and an “CurrentTime” MCP‑tool that is invoked when the user asks about time or date.
|
||
|
||
**Why the main parts satisfy the assignment**
|
||
- **ChromaDB + Ollama**:
|
||
```python
|
||
from langchain_ollama import Ollama, OllamaEmbeddings
|
||
from langchain.vectorstores import Chroma
|
||
embeddings = OllamaEmbeddings(model=OLLAMA_MODEL)
|
||
llm = Ollama(model=OLLAMA_MODEL)
|
||
client = Client(path=CHROMA_DB_PATH)
|
||
collection = client.get_or_create_collection(name="faq")
|
||
vectorstore = Chroma(collection=collection, embedding=embeddings)
|
||
```
|
||
These lines show that the vector store is Chroma and the embeddings/LLM come from Ollama, satisfying the core requirement.
|
||
|
||
- **Retrieval‑QA chain**:
|
||
```python
|
||
retrieval_chain = RetrievalQA.from_chain_type(
|
||
llm=llm,
|
||
chain_type="stuff",
|
||
retriever=vectorstore.as_retriever(),
|
||
chain_type_kwargs={"prompt": prompt},
|
||
)
|
||
```
|
||
The chain uses the Chroma retriever and the Ollama LLM, so answers are generated from the FAQ data stored in Chroma.
|
||
|
||
- **MCP‑tool integration**:
|
||
```python
|
||
def get_current_time(_input: str) -> str:
|
||
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||
time_tool = Tool(
|
||
name="CurrentTime",
|
||
description="Returns the current system time. Useful when the user asks about the time or date.",
|
||
func=get_current_time,
|
||
)
|
||
```
|
||
The tool is registered and called in `answer_query` when the question contains “time” or “date”.
|
||
|
||
- **CLI & web interface**:
|
||
```python
|
||
@cli.command()
|
||
@click.argument("question", nargs=-1, required=True)
|
||
def ask(question, init):
|
||
...
|
||
@app.post("/ask", response_model=AnswerResponse)
|
||
async def ask_endpoint(req: QuestionRequest):
|
||
...
|
||
```
|
||
These provide two simple ways to interact with the bot locally.
|
||
|
||
**Short code excerpts**
|
||
- **`src/main.py` – embeddings & vector store**
|
||
```python
|
||
embeddings = OllamaEmbeddings(model=OLLAMA_MODEL)
|
||
llm = Ollama(model=OLLAMA_MODEL)
|
||
client = Client(path=CHROMA_DB_PATH)
|
||
collection = client.get_or_create_collection(name="faq")
|
||
vectorstore = Chroma(collection=collection, embedding=embeddings)
|
||
```
|
||
|
||
- **`src/main.py` – RetrievalQA chain**
|
||
```python
|
||
retrieval_chain = RetrievalQA.from_chain_type(
|
||
llm=llm,
|
||
chain_type="stuff",
|
||
retriever=vectorstore.as_retriever(),
|
||
chain_type_kwargs={"prompt": prompt},
|
||
)
|
||
```
|
||
|
||
- **`src/main.py` – MCP‑tool**
|
||
```python
|
||
def get_current_time(_input: str) -> str:
|
||
return datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||
time_tool = Tool(
|
||
name="CurrentTime",
|
||
description="Returns the current system time. Useful when the user asks about the time or date.",
|
||
func=get_current_time,
|
||
)
|
||
```
|
||
|
||
- **`src/main.py` – CLI command**
|
||
```python
|
||
@cli.command()
|
||
@click.argument("question", nargs=-1, required=True)
|
||
def ask(question, init):
|
||
...
|
||
```
|
||
|
||
**Honest limitations**
|
||
- The solution assumes an Ollama server is running locally and reachable; no fallback or error handling for connection failures.
|
||
- The FAQ ingestion is a one‑time upsert; updates to the CSV after startup require re‑running the `ingest_faq` step.
|
||
- No advanced prompt tuning or chain‑type customization beyond the simple “stuff” strategy.
|
||
- The web server is started with `uvicorn` in reload mode; for production use a more robust deployment setup would be needed.
|
||
|
||
Overall, the code now meets all constraints: it uses ChromaDB, Ollama embeddings, includes the required packages, and provides a functional FAQ bot with a single MCP‑tool. |