Metal labels वाले लकड़ी के card catalog drawers की कतारें, जैसे Chroma vector database में रखे और index किए गए documents
Photo by Ilya Semenov on Unsplash · source · credits

Chroma Tutorial: RAG के लिए Local Vector Database जो Restart के बाद भी Data रखे

Also available in English: Read this article in English

आप अपने documents को Chroma में embed करते हैं, script restart करते हैं, और collection ख़ाली मिलता है। या किसी document की गलती सुधारकर दोबारा चलाते हैं, फिर भी पुराना text लौटता है। दोनों Chroma का सामान्य व्यवहार हैं। यहाँ एक छोटा, persistent setup है जो इनसे बचाता है। हमने इसे Python में chromadb 1.5.9 के साथ test किया।

सही client चुनें

Chroma client modes: in-memory, persistent और local server
Chroma docs (Chroma Clients) से। यह illustration है, screenshot नहीं।

chromadb.Client() memory में चलता है, इसलिए process बंद होते ही data चला जाता है। chromadb.PersistentClient(path=...) data को disk पर save करता है और start पर फिर load करता है। JavaScript app के लिए chroma run --path ./db से local server चलाएँ और localhost:8000 से जुड़ें।

Documents रखें और query करें

pip install chromadb
import chromadb

client = chromadb.PersistentClient(path="./chroma_db")
docs = client.get_or_create_collection(
    "support-docs",
    configuration={"hnsw": {"space": "cosine"}},
)

docs.upsert(
    ids=["refund-1", "office-1"],
    documents=["Refunds are processed within 5 working days.",
               "Our office is in Pune."],
    metadatas=[{"topic": "billing"}, {"topic": "company"}],
)

hits = docs.query(query_texts=["How long does a refund take?"],
                  n_results=3, where={"topic": "billing"})
print(hits["documents"][0], hits["distances"][0])

यह code क्या करता है:

आम गड़बड़ियाँ ठीक करें

Chroma गड़बड़ियों की table: लक्षण, कारण और हल
Chroma docs (Add Data, Update Data, Troubleshooting) से। यह illustration है, screenshot नहीं।

client.reset() सोच-समझकर ही चलाएँ: यह पूरा database मिटा देता है।

Server-side retrieval के लिए हमारी Qdrant hybrid search गाइड, साफ़ input के लिए Firecrawl Markdown गाइड, जवाब परखने के लिए golden questions पढ़ें, या Chroma टूल पेज देखें।

स्रोत

FAQ

PersistentClient data कहाँ रखता है?

उस folder में जो आप path में देते हैं। Path न दें तो default .chroma है।

add() ने मेरा document update क्यों नहीं किया?

add() पहले से मौजूद IDs को ignore करता है। जोड़ने या बदलने के लिए upsert() इस्तेमाल करें।

क्या embeddings के लिए API key चाहिए?

नहीं। Default all-MiniLM-L6-v2 model local रूप से चलता है।

क्या बाद में embedding model बदल सकते हैं?

नए model का dimension अलग हो तो पुराने collection में जोड़ना fail होगा। नया collection बनाकर दोबारा embed करें।

About the author

Suraj Kumar builds and edits AIUseFlow, a directory of AI tools for vibe coders, agent builders and creators. Guides like this one walk through a practical workflow with cited sources — not a news wire rewrite. How we rank tools.

Get the weekly stack

Rank movers and new AI tools for builders, once a week. Free, no spam, unsubscribe anytime.