Skip to content

Commit f87d3e9

Browse files
fix: Make ungrounded types have a default name when sending to the frontend (#5133)
* Update names in map-comprehension * Make default name for ungrounded types public * Return the default name for ungrounded entity-types * Update backend/onyx/db/entities.py Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
1 parent 72cdada commit f87d3e9

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

backend/onyx/db/entities.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from sqlalchemy.orm import Session
1313

1414
import onyx.db.document as dbdocument
15+
from onyx.db.entity_type import UNGROUNDED_SOURCE_NAME
1516
from onyx.db.models import Document
1617
from onyx.db.models import KGEntity
1718
from onyx.db.models import KGEntityExtractionStaging
@@ -328,7 +329,13 @@ def get_entity_stats_by_grounded_source_name(
328329
.group_by(KGEntityType.grounded_source_name)
329330
.all()
330331
)
332+
333+
# `row.grounded_source_name` is NULLABLE in the database schema.
334+
# Thus, for all "ungrounded" entity-types, we use a default name.
331335
return {
332-
row.grounded_source_name: (row.last_updated, row.entities_count)
336+
(row.grounded_source_name or UNGROUNDED_SOURCE_NAME): (
337+
row.last_updated,
338+
row.entities_count,
339+
)
333340
for row in results
334341
}

backend/onyx/db/entity_type.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from onyx.server.kg.models import EntityType
1212

1313

14-
_UNGROUNDED_SOURCE_NAME = "Ungrounded"
14+
UNGROUNDED_SOURCE_NAME = "Ungrounded"
1515

1616

1717
def get_entity_types_with_grounded_source_name(
@@ -87,7 +87,7 @@ def get_configured_entity_types(db_session: Session) -> dict[str, list[KGEntityT
8787

8888
et_map = defaultdict(list)
8989
for et in ets:
90-
key = et.grounded_source_name or _UNGROUNDED_SOURCE_NAME
90+
key = et.grounded_source_name or UNGROUNDED_SOURCE_NAME
9191
et_map[key].append(et)
9292

9393
return et_map

backend/onyx/server/kg/api.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,19 @@ def get_kg_entity_types(
179179
) -> SourceAndEntityTypeView:
180180
# when using for the first time, populate with default entity types
181181
entity_types = {
182-
key: [EntityType.from_model(et) for et in ets]
183-
for key, ets in get_configured_entity_types(db_session=db_session).items()
182+
source_name: [EntityType.from_model(et) for et in ets]
183+
for source_name, ets in get_configured_entity_types(
184+
db_session=db_session
185+
).items()
184186
}
185187

186188
source_statistics = {
187-
key: SourceStatistics(
188-
source_name=key, last_updated=last_updated, entities_count=entities_count
189+
source_name: SourceStatistics(
190+
source_name=source_name,
191+
last_updated=last_updated,
192+
entities_count=entities_count,
189193
)
190-
for key, (
194+
for source_name, (
191195
last_updated,
192196
entities_count,
193197
) in get_entity_stats_by_grounded_source_name(db_session=db_session).items()

0 commit comments

Comments
 (0)