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

3.9 KiB
Raw Blame History

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 singletool FAQ bot that can be used from a CLI or a tiny FastAPI web interface.
  • The bot uses a RetrievalQA chain powered by the Chroma collection and an “CurrentTime” MCPtool that is invoked when the user asks about time or date.

Why the main parts satisfy the assignment

  • ChromaDB + Ollama:

    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.

  • RetrievalQA chain:

    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.

  • MCPtool integration:

    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:

    @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

    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

    retrieval_chain = RetrievalQA.from_chain_type(
        llm=llm,
        chain_type="stuff",
        retriever=vectorstore.as_retriever(),
        chain_type_kwargs={"prompt": prompt},
    )
    
  • src/main.py MCPtool

    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

    @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 onetime upsert; updates to the CSV after startup require rerunning the ingest_faq step.
  • No advanced prompt tuning or chaintype 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 MCPtool.