Cheap defensive stuff but I'm not going to try and cover a malformed row everywhere

This commit is contained in:
stumpylog
2026-08-13 14:09:10 -07:00
parent e4e48733e1
commit 7d1e2c3164
2 changed files with 10 additions and 3 deletions
+6 -2
View File
@@ -695,7 +695,10 @@ def retrieve_similar_nodes(
filtered = []
for node in results:
document_id = node.metadata.get("document_id")
if document_id is None:
if document_id is None: # pragma: no cover
# Every node the indexing pipeline builds always sets
# document_id; this guards a malformed/partial vec0 row that
# shouldn't occur given the current schema.
continue
if str(document_id) not in allowed_document_ids:
continue
@@ -707,7 +710,8 @@ def _node_document_ids(nodes: list["NodeWithScore"]) -> list[int]:
document_ids: list[int] = []
for node in nodes:
document_id = node.metadata.get("document_id")
if document_id is None:
if document_id is None: # pragma: no cover
# See the matching guard in retrieve_similar_nodes() above.
continue
try:
document_ids.append(int(document_id))
+4 -1
View File
@@ -108,7 +108,10 @@ def _node_document_weights(nodes: list["NodeWithScore"]) -> dict[int, float]:
weights: dict[int, float] = defaultdict(float)
for node in nodes:
document_id = node.metadata.get("document_id")
if document_id is None:
if document_id is None: # pragma: no cover
# Every node the indexing pipeline builds always sets
# document_id; this guards a malformed/partial vec0 row that
# shouldn't occur given the current schema.
continue
try:
weights[int(document_id)] += float(node.score or 0.0)