Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tweak 2 #885

Merged
merged 1 commit into from
Aug 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 0 additions & 21 deletions r2r/main/api/routes/ingestion/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import yaml
from fastapi import Depends, File, Form, UploadFile
from fastapi.openapi.models import Example

from r2r.base import ChunkingConfig, R2RException
from r2r.base.api.models.ingestion.responses import WrappedIngestionResponse
Expand All @@ -31,26 +30,6 @@ def load_openapi_extras(self):
yaml_content = yaml.safe_load(yaml_file)
return yaml_content

# paths = yaml_content.get("paths", {})

# def extract_descriptions(endpoint):
# params = endpoint.get("requestBody", {}).get("content", {}).get("multipart/form-data", {}).get("schema", {}).get("properties", {})
# return {k: v.get("description", "") for k, v in params.items()}

# ingest_files = paths.get("/v1/ingest_files", {})
# # update_files = paths.get("/v1/update_files", {}).get("post", {})

# return {
# "ingest_files": {
# # "descriptions": extract_descriptions(ingest_files),
# # "operation": ingest_files
# },
# # "update_files": {
# # "descriptions": extract_descriptions(update_files),
# # "operation": update_files
# # }
# }

def setup_routes(self):
# Note, we use the following verbose input parameters because FastAPI struggles to handle `File` input and `Body` inputs
# at the same time. Therefore, we must ues `Form` inputs for the metadata, document_ids, and versions inputs.
Expand Down
20 changes: 8 additions & 12 deletions r2r/main/api/routes/restructure/base.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import List, Optional

from fastapi import Depends
from fastapi import Depends, Form

from r2r.main.api.routes.base_router import BaseRouter
from r2r.main.engine import R2REngine
Expand All @@ -15,20 +15,16 @@ def setup_routes(self):
@self.router.post("/enrich_graph")
@self.base_endpoint
async def enrich_graph(
query: str,
entity_types: Optional[List[str]] = None,
relationships: Optional[List[str]] = None,
generation_config: Optional[dict] = None,
auth_user=(
Depends(self.engine.providers.auth.auth_wrapper)
if self.engine.providers.auth
else None
),
):
request = {
"query": query,
"entity_types": entity_types,
"relationships": relationships,
"generation_config": generation_config,
}
return await self.engine.enrich_graph(request)
"""
Perform graph enrichment, e.g. GraphRAG, over the ingested documents.

Returns:
Dict[str, Any]: Results of the graph enrichment process.
"""
return await self.engine.aenrich_graph()
43 changes: 1 addition & 42 deletions r2r/main/services/restructure_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,10 @@ def __init__(
logging_connection,
)

async def enrich_graph(
self, documents: List[Document] = None
) -> Dict[str, Any]:
async def enrich_graph(self) -> Dict[str, Any]:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call to 'self.pipelines.kg_enrichment_pipeline.run' should be awaited since 'enrich_graph' is an async function. Add 'await' before the call to ensure proper asynchronous execution.

"""
Perform graph enrichment on the given documents.

Args:
documents (List[Document]): List of documents to enrich.

Returns:
Dict[str, Any]: Results of the graph enrichment process.
"""
Expand All @@ -54,39 +49,3 @@ async def enrich_graph(
raise R2RException(
status_code=500, message=f"Graph enrichment failed: {str(e)}"
)

async def query_graph(self, query: str) -> Dict[str, Any]:
"""
Query the knowledge graph.

Args:
query (str): The query to run against the knowledge graph.

Returns:
Dict[str, Any]: Results of the graph query.
"""
try:
results = self.providers.database.graph.query(query)
return {"results": results}
except Exception as e:
logger.error(f"Error querying graph: {str(e)}")
raise R2RException(
status_code=500, message=f"Graph query failed: {str(e)}"
)

async def get_graph_statistics(self) -> Dict[str, Any]:
"""
Get statistics about the knowledge graph.

Returns:
Dict[str, Any]: Statistics about the knowledge graph.
"""
try:
stats = self.providers.database.graph.get_statistics()
return stats
except Exception as e:
logger.error(f"Error getting graph statistics: {str(e)}")
raise R2RException(
status_code=500,
message=f"Failed to retrieve graph statistics: {str(e)}",
)
Loading