cdupland commited on
Commit
5a8a35f
·
1 Parent(s): 6786331

fix bug on id memory

Browse files
Files changed (2) hide show
  1. main.py +5 -2
  2. rag.py +6 -4
main.py CHANGED
@@ -192,10 +192,13 @@ def delete_document(enterprise_id: str, user_id: str):
192
 
193
  @app.delete("/documents/memory/{enterprise_id}/{user_id}/{info_id}")
194
  def delete_document(enterprise_id: str, user_id: str, info_id: str):
195
- try:
 
196
  for ids in index.list(prefix=f"{info_id}", namespace=enterprise_id):
 
 
197
  index.delete(ids=ids, namespace=enterprise_id)
198
- return {"message": "Document deleted", "chunks_deleted": ids}
199
  except Exception as e:
200
  raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
201
 
 
192
 
193
  @app.delete("/documents/memory/{enterprise_id}/{user_id}/{info_id}")
194
  def delete_document(enterprise_id: str, user_id: str, info_id: str):
195
+ try:
196
+ all_ids = []
197
  for ids in index.list(prefix=f"{info_id}", namespace=enterprise_id):
198
+ # all_ids.extend(ids)
199
+ print(ids)
200
  index.delete(ids=ids, namespace=enterprise_id)
201
+ return {"message": "Document deleted", "chunks_deleted": all_ids}
202
  except Exception as e:
203
  raise HTTPException(status_code=500, detail=f"An error occurred: {str(e)}")
204
 
rag.py CHANGED
@@ -94,14 +94,16 @@ def add_to_knowledge_base(enterprise_id,information,index,enterprise_name,user_i
94
  embedding = OpenAIEmbeddings(model="text-embedding-3-large")
95
  vector_store = PineconeVectorStore(index=index, embedding=embedding,namespace=enterprise_id)
96
 
 
 
 
97
  document = Document(
98
  page_content=information,
99
- metadata={"filename":"knowledge_base","file_type":"text", "filename_id":"knowledge_base", "entreprise_name":enterprise_name, "user_id":user_id},
100
  )
101
 
102
- uuid = f"kb_{user_id}_{uuid4()}"
103
-
104
- vector_store.add_documents(documents=[document], id=uuid)
105
  return uuid
106
 
107
  except Exception as e:
 
94
  embedding = OpenAIEmbeddings(model="text-embedding-3-large")
95
  vector_store = PineconeVectorStore(index=index, embedding=embedding,namespace=enterprise_id)
96
 
97
+ uuids = []
98
+ uuid = f"kb_{user_id}_{uuid4()}"
99
+
100
  document = Document(
101
  page_content=information,
102
+ metadata={"filename":"knowledge_base","file_type":"text", "filename_id":uuid, "entreprise_name":enterprise_name, "user_id":user_id},
103
  )
104
 
105
+ uuids.append(uuid)
106
+ vector_store.add_documents(documents=[document], ids=uuids)
 
107
  return uuid
108
 
109
  except Exception as e: