koffiwind commited on
Commit
126e90e
·
1 Parent(s): 5fa590d

delete collection before inserting docs

Browse files
Files changed (2) hide show
  1. aimakerspace/vectordatabase.py +18 -0
  2. app.py +1 -0
aimakerspace/vectordatabase.py CHANGED
@@ -34,6 +34,24 @@ class VectorDatabase:
34
  f"Inserted {len(texts)} documents into collection '{self.collection_name}'."
35
  )
36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
  def search_similar(self, query_text: str):
38
  search_result = self.client.query(
39
  collection_name=self.collection_name,
 
34
  f"Inserted {len(texts)} documents into collection '{self.collection_name}'."
35
  )
36
 
37
+ def _delete_collection(self):
38
+ """
39
+ Delete a collection from the Qdrant database.
40
+
41
+ Args:
42
+ collection_name (str): Name of the collection to delete.
43
+ """
44
+ # Check if the collection exists
45
+ collections = self.client.get_collections()
46
+ collection_names = [collection.name for collection in collections.collections]
47
+
48
+ if self.collection_name in collection_names:
49
+ # Delete the collection
50
+ self.client.delete_collection(collection_name)
51
+ print(f"Collection '{collection_name}' deleted.")
52
+ else:
53
+ print(f"Collection '{collection_name}' does not exist.")
54
+
55
  def search_similar(self, query_text: str):
56
  search_result = self.client.query(
57
  collection_name=self.collection_name,
app.py CHANGED
@@ -31,6 +31,7 @@ class RetrievalAugmentedQAPipeline:
31
  def __init__(self, llm: ChatOpenAI(), vector_db_retriever: VectorDatabase) -> None:
32
  self.llm = llm
33
  self.vector_db_retriever = vector_db_retriever
 
34
 
35
  async def arun_pipeline(self, user_query: str):
36
  context_data = self.vector_db_retriever.search_similar(user_query)
 
31
  def __init__(self, llm: ChatOpenAI(), vector_db_retriever: VectorDatabase) -> None:
32
  self.llm = llm
33
  self.vector_db_retriever = vector_db_retriever
34
+ self.vector_db_retriever.delete_collection()
35
 
36
  async def arun_pipeline(self, user_query: str):
37
  context_data = self.vector_db_retriever.search_similar(user_query)