I am using cromadb for vectorization in my flask application.
below is my vectordb.py code:-
import os
import shutil
from dotenv import load_dotenv
load_dotenv()
import re
from llama_index import (
SimpleDirectoryReader,
VectorStoreIndex,
ServiceContext,
StorageContext
)
from llama_index.vector_stores import ChromaVectorStore
from llama_index.llms import OpenAI
from llama_index.embeddings import OpenAIEmbedding
from llama_index.prompts import PromptTemplate
import chromadb
import logging
import sys
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout))
def regenrate_tokens(collection_name, persist_directory):
if os.path.isdir(persist_directory):
print("directory existed, replacing previous directory")
# Close the chroma_client connection
chroma_client = chromadb.PersistentClient(path=persist_directory)
chroma_client.close() # Ensure the database connection is closed
shutil.rmtree(persist_directory)
print("Recreating Embeddings...")
chroma_client = chromadb.PersistentClient(path=persist_directory)
embed_model = OpenAIEmbedding()
documents = SimpleDirectoryReader('./static/upload/').load_data()
chroma_collection = chroma_client.get_or_create_collection(collection_name)
vector_store = ChromaVectorStore(chroma_collection=chroma_collection)
storage_context = StorageContext.from_defaults(vector_store=vector_store)
service_context = ServiceContext.from_defaults(embed_model=embed_model)
index = VectorStoreIndex.from_documents(
documents, storage_context=storage_context, service_context=service_context
)
return 'Data refreshed, you can ask the questions. 😄'
getting this error in the UIenter image description here ‘SegmentAPI’ object has no attribute ‘close’
I am uploading a zip file containing pdf for vectorization.
I want to get a result according to my query but getting this error
New contributor
rita pradhan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.