Skip to content
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
9 changes: 8 additions & 1 deletion backend/onyx/db/entities.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from sqlalchemy.orm import Session

import onyx.db.document as dbdocument
from onyx.db.entity_type import UNGROUNDED_SOURCE_NAME
from onyx.db.models import Document
from onyx.db.models import KGEntity
from onyx.db.models import KGEntityExtractionStaging
Expand Down Expand Up @@ -328,7 +329,13 @@ def get_entity_stats_by_grounded_source_name(
.group_by(KGEntityType.grounded_source_name)
.all()
)

# `row.grounded_source_name` is NULLABLE in the database schema.
# Thus, for all "ungrounded" entity-types, we use a default name.
return {
row.grounded_source_name: (row.last_updated, row.entities_count)
(row.grounded_source_name or UNGROUNDED_SOURCE_NAME): (
row.last_updated,
row.entities_count,
)
for row in results
}
4 changes: 2 additions & 2 deletions backend/onyx/db/entity_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from onyx.server.kg.models import EntityType


_UNGROUNDED_SOURCE_NAME = "Ungrounded"
UNGROUNDED_SOURCE_NAME = "Ungrounded"


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

et_map = defaultdict(list)
for et in ets:
key = et.grounded_source_name or _UNGROUNDED_SOURCE_NAME
key = et.grounded_source_name or UNGROUNDED_SOURCE_NAME
et_map[key].append(et)

return et_map
Expand Down
14 changes: 9 additions & 5 deletions backend/onyx/server/kg/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,19 @@ def get_kg_entity_types(
) -> SourceAndEntityTypeView:
# when using for the first time, populate with default entity types
entity_types = {
key: [EntityType.from_model(et) for et in ets]
for key, ets in get_configured_entity_types(db_session=db_session).items()
source_name: [EntityType.from_model(et) for et in ets]
for source_name, ets in get_configured_entity_types(
db_session=db_session
).items()
}

source_statistics = {
key: SourceStatistics(
source_name=key, last_updated=last_updated, entities_count=entities_count
source_name: SourceStatistics(
source_name=source_name,
last_updated=last_updated,
entities_count=entities_count,
)
for key, (
for source_name, (
last_updated,
entities_count,
) in get_entity_stats_by_grounded_source_name(db_session=db_session).items()
Expand Down
Loading