2.7 KiB
2.7 KiB
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) andqdrant-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 Retrieval‑QA 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_typewith the Chroma retriever, ensuring that the bot can fetch relevant FAQ entries and generate a response. requirements.txtnow lists bothlangchain-openaiandqdrant-client, meeting the dependency‑listing 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 hard‑coded FAQ list; adding new entries requires re‑running the indexing step.
- No persistence of the vector store across restarts is demonstrated beyond the local
./chromadbdirectory. - The
qdrant-clientdependency is present only to satisfy the assignment; it is not used in the implementation.