Skip to content

Commit

Permalink
modify the update query
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyaspimpalgaonkar committed Oct 20, 2024
1 parent 0ed7481 commit 0af920d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion py/core/pipes/kg/deduplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ async def kg_named_entity_deduplication(
logger.info(
f"KGEntityDeduplicationPipe: Upserting {len(deduplicated_entities_list)} deduplicated entities for collection {collection_id}"
)
await self.kg_provider.add_entities(
await self.kg_provider.add_entity_descriptions(
deduplicated_entities_list,
table_name="entity_deduplicated",
conflict_columns=["name", "collection_id", 'attributes'],
Expand Down
8 changes: 2 additions & 6 deletions py/core/pipes/kg/deduplication_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,16 +108,12 @@ async def _prepare_and_upsert_entities(
)

for i, entity in enumerate(entities_batch):
entity.description_embedding = embeddings[i]
entity.description_embedding = str(embeddings[i]) # type: ignore
entity.collection_id = collection_id
entity.attributes = {}

print(entities_batch)

result = await self.kg_provider.add_entities(
result = await self.kg_provider.add_entity_descriptions(
entities_batch,
table_name="entity_deduplicated",
conflict_columns=["name", "collection_id", 'attributes'],
)

logger.info(
Expand Down
15 changes: 15 additions & 0 deletions py/core/providers/kg/postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -1270,3 +1270,18 @@ async def get_triple_count(
WHERE {" AND ".join(conditions)}
"""
return (await self.fetch_query(QUERY, params))[0]["count"]

async def add_entity_descriptions(self, entities: list[Entity]):

query = f"""
UPDATE {self._get_table_name("entity_deduplicated")}
SET description = $3, description_embedding = $4
WHERE name = $1 AND collection_id = $2
"""

inputs = [
(entity.name, entity.collection_id, entity.description, entity.description_embedding)
for entity in entities
]

await self.execute_many(query, inputs)

0 comments on commit 0af920d

Please sign in to comment.