Knowledge core delete

This commit is contained in:
Cyber MacGeddon 2025-05-06 23:38:21 +01:00
parent 51b23ab1ca
commit 0257d2de6b
3 changed files with 61 additions and 20 deletions

View file

@ -18,28 +18,22 @@ class KnowledgeManager:
cassandra_host, cassandra_user, cassandra_password, keyspace cassandra_host, cassandra_user, cassandra_password, keyspace
) )
async def delete_kg_core(self, request): async def delete_kg_core(self, request, respond):
print("Updating doc...", flush=True) print("Deleting core...", flush=True)
# You can't update the document ID, user or kind. await self.table_store.delete_kg_core(
request.user, request.id
)
if not await self.table_store.document_exists( await respond(
request.document_metadata.user, KnowledgeResponse(
request.document_metadata.id error = None,
): ids = None,
raise RuntimeError("Document does not exist") eos = False,
triples = None,
await self.table_store.update_document(request.document_metadata) graph_embeddings = None,
)
print("Update complete", flush=True)
return LibrarianResponse(
error = None,
document_metadata = None,
content = None,
document_metadatas = None,
processing_metadatas = None,
) )
async def fetch_kg_core(self, request, respond): async def fetch_kg_core(self, request, respond):

View file

@ -63,5 +63,6 @@ class KnowledgeRequestor(ServiceRequestor):
"eos": True "eos": True
}, True }, True
raise RuntimeError("Unexpected case") # Empty case, return from successful delete.
return {}, True

View file

@ -181,6 +181,16 @@ class KnowledgeTableStore:
WHERE user = ? AND document_id = ? WHERE user = ? AND document_id = ?
""") """)
self.delete_triples_stmt = self.cassandra.prepare("""
DELETE FROM triples
WHERE user = ? AND document_id = ?
""")
self.delete_graph_embeddings_stmt = self.cassandra.prepare("""
DELETE FROM graph_embeddings
WHERE user = ? AND document_id = ?
""")
async def add_triples(self, m): async def add_triples(self, m):
when = int(time.time() * 1000) when = int(time.time() * 1000)
@ -343,6 +353,42 @@ class KnowledgeTableStore:
return lst return lst
async def delete_kg_core(self, user, document_id):
print("Delete kg cores...")
while True:
try:
resp = self.cassandra.execute(
self.delete_triples_stmt,
(user, document_id)
)
break
except Exception as e:
print("Exception:", type(e))
print(f"{e}, retry...", flush=True)
await asyncio.sleep(1)
while True:
try:
resp = self.cassandra.execute(
self.delete_graph_embeddings_stmt,
(user, document_id)
)
break
except Exception as e:
print("Exception:", type(e))
print(f"{e}, retry...", flush=True)
await asyncio.sleep(1)
async def get_triples(self, user, document_id, receiver): async def get_triples(self, user, document_id, receiver):
print("Get triples...") print("Get triples...")