Created an AI chatbot using ChromaDB and Sentence-Transformers. These tools made the whole process smooth and efficient, and I wanted to share my experience in hopes that it might help someone else starting out with similar projects.
Steps I Took to Build the Chatbot:
I used sentence-transformers to convert text data into embeddings and ChromaDB for vector storage.
so install these dependencies..
pip install -U sentence-transformers
pip install chromadb
Next
import chromadb
chroma_client = chromadb.Client()
collection = chroma_client.create_collection(name="data")
Don't forget to load your dataset
Using Sentence-Transformers, I generated embeddings for my dataset:
for index,text in data.iterrows():
res=text['Answer']
embedding = model.encode(res)
collection.add(
documents=[str(res)],
embeddings=[embedding.tolist()],
ids=[str(index)],
metadatas=[{'text':res}]
)
*Query and Response: *
The chatbot listens for user input, converts the query into an embedding, and uses ChromaDB to find the closest match in the stored embeddings. Hereβs the basic query
def get_response(text):
res=model.encode(text)
result=collection.query(
query_embeddings=[res.tolist()],
n_results=1
)
return result
That's it ,If you pass any text relevant to your dataset it'll response for you which is has close distance
πππππ
I'm excited to introduce Terminal Troubleshooters β a dynamic Slack community for tech enthusiasts to learn, share, and grow together! Our mission is to build a collaborative space where you can:
β¨ Share daily tech insights and experiences
π‘ Discuss innovative ideas and industry trends
π£οΈ Enhance communication skills through engaging conversations
π€ Connect with like-minded professionals and expand your network
Community Link:
Top comments (0)