Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyaspimpalgaonkar committed Oct 5, 2024
1 parent df6bd31 commit a6d9630
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions py/core/providers/kg/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,33 +320,33 @@ async def add_kg_extractions(
return (total_entities, total_relationships)

async def get_entity_map(
self, offset: int, limit: int, document_ids: list[UUID]
self, offset: int, limit: int, document_id: UUID
) -> Dict[str, Dict[str, List[Dict[str, Any]]]]:

QUERY1 = f"""
WITH entities_list AS (
SELECT DISTINCT name
FROM {self._get_table_name("entity_raw")}
WHERE document_id = ANY($1)
WHERE document_id = $1
ORDER BY name ASC
LIMIT {limit} OFFSET {offset}
)
SELECT e.name, e.description, e.category,
(SELECT array_agg(DISTINCT x) FROM unnest(e.extraction_ids) x) AS extraction_ids,
(SELECT array_agg(DISTINCT x) FROM unnest(e.document_ids) x) AS document_ids
e.document_id
FROM {self._get_table_name("entity_raw")} e
JOIN entities_list el ON e.name = el.name
GROUP BY e.name, e.description, e.category, e.extraction_ids, e.entity_id, e.document_ids
GROUP BY e.name, e.description, e.category, e.extraction_ids, e.entity_id, e.document_id
ORDER BY e.name;"""

entities_list = await self.fetch_query(QUERY1, [document_ids])
entities_list = await self.fetch_query(QUERY1, [document_id])
entities_list = [
Entity(
name=entity["name"],
description=entity["description"],
category=entity["category"],
extraction_ids=entity["extraction_ids"],
document_ids=entity["document_ids"],
document_id=entity["document_id"],
)
for entity in entities_list
]
Expand All @@ -368,7 +368,7 @@ async def get_entity_map(
ORDER BY t.subject, t.predicate, t.object;
"""

triples_list = await self.fetch_query(QUERY2, [document_ids])
triples_list = await self.fetch_query(QUERY2, [document_id])
triples_list = [
Triple(
subject=triple["subject"],
Expand Down

0 comments on commit a6d9630

Please sign in to comment.