Spaces:
Runtime error
Runtime error
Oviya commited on
Commit Β·
44abeb3
1
Parent(s): 43f037b
fix
Browse files55 unmodified lines565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710855 unmodified linesembedding_function=get_embeddings(),)return _vectorstoredef get_vectorstore_for(db_level: Optional[str] = None):key = (db_level or "").strip().lower()if key in ("low", "mid", "high"):persist_dir = os.path.join(CHROMA_ROOT, key)else:persist_dir = CHROMA_DIRprint(f"[RAG] Using Chroma from: {persist_dir}")client = chromadb.PersistentClient(path=persist_dir)# Show collections availablecollections = client.list_collections()print(f"Available collections: {[c.name for c in collections]}")# Pick the default collection (first one)if not collections:print("β No collections found.")return Nonecollection = client.get_collection(collections[0].name)print(f"β Loaded Chroma collection: {collection.name}")return collection# def get_vectorstore_for(db_level: Optional[str] = None):# """# Return a persistent Chroma vectorstore for the requested db_level.# db_level in {"low","mid","high"} β ./chroma/<db_level># else β fall back to your original CHROMA_DIR (single-store).# """# key = (db_level or "").strip().lower()# if key in ("low", "mid", "high"):# persist_dir = os.path.join(CHROMA_ROOT, key)# print(f"[RAG] get_vectorstore_for('{key}') -> {persist_dir}")# else:# persist_dir = CHROMA_DIR # fallback# print(f"[DEBUG] Using Chroma folder for level '{key or 'default'}' β {persist_dir}")# print(f"[RAG] get_vectorstore_for(None) -> default ({CHROMA_DIR})")# if key not in _vectorstores:# print(f"πΉ Loading Chroma at: {persist_dir}")# _vectorstores[key] = Chroma(# persist_directory=persist_dir,# embedding_function=get_embeddings(),# )# return _vectorstores[key]def get_client():"""Initialize and return a singleton OpenAI client (uses OPENAI_API_KEY)."""55 unmodified lines565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510655 unmodified linesembedding_function=get_embeddings(),)return _vectorstore# new# def get_vectorstore_for(db_level: Optional[str] = None):# key = (db_level or "").strip().lower()# if key in ("low", "mid", "high"):# persist_dir = os.path.join(CHROMA_ROOT, key)# else:# persist_dir = CHROMA_DIR# print(f"[RAG] Using Chroma from: {persist_dir}")# client = chromadb.PersistentClient(path=persist_dir)# # Show collections available# collections = client.list_collections()# print(f"Available collections: {[c.name for c in collections]}")# # Pick the default collection (first one)# if not collections:# print("β No collections found.")# return None# collection = client.get_collection(collections[0].name)# print(f"β Loaded Chroma collection: {collection.name}")# return collectiondef get_vectorstore_for(db_level: Optional[str] = None):key = (db_level or "").strip().lower()persist_dir = os.path.join(CHROMA_ROOT, key) if key in ("low", "mid", "high") else CHROMA_DIRprint(f"[RAG] Using LangChain Chroma at: {persist_dir}")os.makedirs(persist_dir, exist_ok=True)# Discover the existing collection name (created during ingest)client = chromadb.PersistentClient(path=persist_dir)cols = client.list_collections()collection_name = cols[0].name if cols else "langchain" # fallback if emptyprint(f"[RAG] Attaching to collection: {collection_name}")# Return a LangChain vectorstore bound to that collectionreturn Chroma(client=client,collection_name=collection_name,embedding_function=get_embeddings(),)def get_client():"""Initialize and return a singleton OpenAI client (uses OPENAI_API_KEY)."""
ragg/rag_llm.py+37-39