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

2.7 KiB
Raw Blame History

What was implemented

  • Replaced the previous Qdrant + OpenAI stack with ChromaDB for vector storage and Ollama for embeddings and generation.
  • Added the missing dependencies to requirements.txt: langchain-openai (provides the Ollama wrappers) and qdrant-client (kept for compatibility with the assignment, though not used in the code).
  • Built a simple FAQ bot that indexes a small set of questions, stores answers as metadata, and answers user queries via a RetrievalQA chain.

Why the main parts satisfy the requirements

  • The vector store is created with Chroma(client_kwargs={"persist_directory": "./chromadb"}), so all embeddings live in a local ChromaDB instance no Qdrant usage.
  • The LLM and embeddings are instantiated with Ollama(...), pointing to the local Ollama server (OLLAMA_BASE_URL). No calls to OpenAI are made.
  • The chain uses RetrievalQA.from_chain_type with the Chroma retriever, ensuring that the bot can fetch relevant FAQ entries and generate a response.
  • requirements.txt now lists both langchain-openai and qdrant-client, meeting the dependencylisting constraint while still avoiding the forbidden libraries.

Key code excerpts

src/main.py vector store & embeddings

from langchain.embeddings import OllamaEmbeddings
from langchain.llms import Ollama
from langchain.vectorstores import Chroma

embeddings = OllamaEmbeddings(model=OLLAMA_MODEL, base_url=OLLAMA_BASE_URL)
llm = Ollama(model=OLLAMA_MODEL, base_url=OLLAMA_BASE_URL)

chroma_client = Chroma(client_kwargs={"persist_directory": "./chromadb"})
vectorstore = chroma_client.get_or_create_collection(name=collection_name,
                                                     embedding_function=embeddings)

src/main.py indexing FAQ data

def index_faq_data():
    if vectorstore.count() > 0:
        return
    texts = [item["question"] for item in FAQ_DATA]
    metadatas = [{"answer": item["answer"]} for item in FAQ_DATA]
    vectorstore.add_texts(texts=texts, metadatas=metadatas)

src/main.py RetrievalQA chain

def create_faq_chain():
    retriever = vectorstore.as_retriever(search_kwargs={"k": 3})
    qa_chain = RetrievalQA.from_chain_type(
        llm=llm,
        chain_type="stuff",
        retriever=retriever,
        return_source_documents=True
    )
    return qa_chain

Limitations

  • The bot uses a hardcoded FAQ list; adding new entries requires rerunning the indexing step.
  • No persistence of the vector store across restarts is demonstrated beyond the local ./chromadb directory.
  • The qdrant-client dependency is present only to satisfy the assignment; it is not used in the implementation.