Skip to content

Commit

Permalink
Fix weight casting during graph extraction (#1016)
Browse files Browse the repository at this point in the history
* Fix weight casting during graph extraction

* Format

* Format
  • Loading branch information
AlonsoGuevara authored Aug 24, 2024
1 parent e15df44 commit 55e74a0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
4 changes: 4 additions & 0 deletions .semversioner/next-release/patch-20240823233325895089.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": "patch",
"description": "Fix weight casting during graph extraction"
}
11 changes: 5 additions & 6 deletions graphrag/index/graph/extractors/graph/graph_extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"""A module containing 'GraphExtractionResult' and 'GraphExtractor' models."""

import logging
import numbers
import re
import traceback
from collections.abc import Mapping
Expand Down Expand Up @@ -248,11 +247,11 @@ async def _process_results(
target = clean_str(record_attributes[2].upper())
edge_description = clean_str(record_attributes[3])
edge_source_id = clean_str(str(source_doc_id))
weight = (
float(record_attributes[-1])
if isinstance(record_attributes[-1], numbers.Number)
else 1.0
)
try:
weight = float(record_attributes[-1])
except ValueError:
weight = 1.0

if source not in graph.nodes():
graph.add_node(
source,
Expand Down

0 comments on commit 55e74a0

Please sign in to comment.