Skip to content

Commit

Permalink
rm pull
Browse files Browse the repository at this point in the history
  • Loading branch information
emrgnt-cmplxty committed Dec 1, 2024
1 parent 8e36251 commit 2fd5274
Showing 1 changed file with 0 additions and 81 deletions.
81 changes: 0 additions & 81 deletions py/core/main/api/v3/graph_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -1601,87 +1601,6 @@ async def update_community(
rating_explanation=rating_explanation,
)

async def _pull(collection_id: UUID, auth_user):
if (
not auth_user.is_superuser
and collection_id not in auth_user.graph_ids
):
raise R2RException(
"The currently authenticated user does not have access to the specified graph.",
403,
)

list_graphs_response = await self.services["kg"].list_graphs(
# user_ids=None,
graph_ids=[collection_id],
offset=0,
limit=1,
)
if len(list_graphs_response["results"]) == 0:
raise R2RException("Graph not found", 404)
collection_id = list_graphs_response["results"][0].collection_id
documents = []
document_req = (
await self.providers.database.collections_handler.documents_in_collection(
collection_id, offset=0, limit=100
)
)["results"]
documents.extend(document_req)
while len(document_req) == 100:
document_req = (
await self.providers.database.collections_handler.documents_in_collection(
collection_id, offset=len(documents), limit=100
)
)["results"]
documents.extend(document_req)

success = False

for document in documents:
if (
not auth_user.is_superuser
and document.id
not in auth_user.document_ids # TODO - extend to include checks on collections
):
raise R2RException(
f"The currently authenticated user does not have access to document {document.id}",
403,
)
entities = (
await self.providers.database.graph_handler.entities.get(
document.id, store_type="document"
)
)
has_document = (
await self.providers.database.graph_handler.has_document(
collection_id, document.id
)
)
if has_document:
logger.info(
f"Document {document.id} is already in graph {collection_id}, skipping."
)
continue
if len(entities[0]) == 0:
logger.warning(
f"Document {document.id} has no entities, extraction may not have been called, skipping."
)
continue

success = (
await self.providers.database.graph_handler.add_documents(
id=collection_id,
document_ids=[
document.id
], # [doc.id for doc in documents]
)
)
if not success:
logger.warning(
f"No documents were added to graph {collection_id}, marking as failed."
)
return success

@self.router.post(
"/graphs/{collection_id}/pull",
summary="Pull latest entities to the graph",
Expand Down

0 comments on commit 2fd5274

Please sign in to comment.