What it does
Answers FAQs in Hindi or English
Cites source documents
REST API endpoint
Handles multi-language queries
Escalates unknown queries
Stack
PythonLlamaIndexChromaDBFastAPI
Deploy on
✓ Google Colab✓ Render✓ Railway
Full source code
Install commands are in the top comments. Copy and run.
import chromadb
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.vector_stores.chroma import ChromaVectorStore
from llama_index.core import StorageContext
from fastapi import FastAPI
from pydantic import BaseModel
app = FastAPI()
cc = chromadb.PersistentClient(path='./support_db')
vs = ChromaVectorStore(chroma_collection=cc.get_or_create_collection('support_docs'))
index = VectorStoreIndex.from_documents(
SimpleDirectoryReader('./support_docs').load_data(),
storage_context=StorageContext.from_defaults(vector_store=vs)
)
engine = index.as_query_engine(similarity_top_k=3)
class Query(BaseModel):
question: str
language: str = 'en'
@app.post('/ask')
async def ask(q: Query):
prefix = 'Answer in Hindi if language is hi, else English. Be concise. '
resp = engine.query(prefix + q.question)
return {'answer': str(resp), 'sources': [n.metadata.get('file_name') for n in resp.source_nodes]}