Add TwoStepExtraction: ordered entity extraction with pluggable NER + LLM relationships#189
Draft
Add TwoStepExtraction: ordered entity extraction with pluggable NER + LLM relationships#189
Conversation
…vers Co-authored-by: galshubeli <124919062+galshubeli@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] [187] Implement order in the entity extraction process
Add TwoStepExtraction: ordered entity extraction with pluggable NER + LLM relationships
Mar 18, 2026
| await asyncio.sleep( | ||
| self.config.retry_delay * (attempt + 1) | ||
| ) | ||
| raise last_exc # type: ignore[misc] |
| f"retrying in {delay}s: {exc}" | ||
| ) | ||
| await asyncio.sleep(delay) | ||
| raise last_exc # type: ignore[misc] |
| f"retrying in {delay}s: {exc}" | ||
| ) | ||
| await asyncio.sleep(delay) | ||
| raise last_exc # type: ignore[misc] |
| f"retrying in {delay}s: {exc}" | ||
| ) | ||
| await asyncio.sleep(delay) | ||
| raise last_exc # type: ignore[misc] |
| if not is_valid_entity_name(source) or not is_valid_entity_name(target): | ||
| continue | ||
|
|
||
| weight = 1.0 |
Comment on lines
+376
to
+380
| "MATCH (dup:__Entity__ {id: $dup_id})-[r:RELATES]->(b:__Entity__) " | ||
| "WHERE b.id <> $survivor_id " | ||
| "MERGE (s:__Entity__ {id: $survivor_id})-[nr:RELATES]->(b) " | ||
| "SET nr += properties(r) " | ||
| "DELETE r", |
Comment on lines
+382
to
+386
| "MATCH (a:__Entity__)-[r:RELATES]->(dup:__Entity__ {id: $dup_id}) " | ||
| "WHERE a.id <> $survivor_id " | ||
| "MERGE (a)-[nr:RELATES]->(s:__Entity__ {id: $survivor_id}) " | ||
| "SET nr += properties(r) " | ||
| "DELETE r", |
Comment on lines
+388
to
+390
| "MATCH (dup:__Entity__ {id: $dup_id})-[r:MENTIONED_IN]->(c:Chunk) " | ||
| "MERGE (s:__Entity__ {id: $survivor_id})-[:MENTIONED_IN]->(c) " | ||
| "DELETE r", |
Comment on lines
+474
to
+477
| "MATCH (dup:__Entity__ {id: $dup_id})-[r:RELATES]->(b:__Entity__) " | ||
| "WHERE b.id <> $survivor_id " | ||
| "MERGE (s:__Entity__ {id: $survivor_id})-[nr:RELATES]->(b) " | ||
| "SET nr += properties(r) DELETE r", |
Comment on lines
+478
to
+481
| "MATCH (a:__Entity__)-[r:RELATES]->(dup:__Entity__ {id: $dup_id}) " | ||
| "WHERE a.id <> $survivor_id " | ||
| "MERGE (a)-[nr:RELATES]->(s:__Entity__ {id: $survivor_id}) " | ||
| "SET nr += properties(r) DELETE r", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Implements the new composable
TwoStepExtractionstrategy from PR #187, replacing the oldMergedExtraction/SchemaGuidedExtractionwith a structured 2-step pipeline: pluggable NER (step 1) → LLM verify + relationship extraction (step 2).New extraction strategy
TwoStepExtraction— orchestrates the 2-step pipeline with optional coreference resolution per chunk; respectsschema.entitiesto override entity typesEntityExtractor— routes to GLiNER2 (default, local), LLM-based NER, or any custompredict_entities()modelCorefResolver/FastCorefResolver— optional pre-processing step; uses character-offset replacement (notstr.replace) to correctly handle overlapping spans and possessives_entity_utils— shared name validation, type-qualified entity ID computation, type normalization_prompts— NER and verify+relationship prompt templatesKey correctness properties
properties["rel_type"](not"type") — required byGraphRelationship.to_fact_text()and downstream embeddingtry/finally-style block, not applied globallyUsage
Repo restructuring
Migrates from the legacy flat
graphrag_sdk/package layout to thegraphrag_sdk/src/layout introduced in the staging branch; removes the old conflicting package files.Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
huggingface.co/usr/bin/python python -m pytest tests/ -v --no-header --ignore=tests/test_integration.py --ignore=tests/test_graph_store.py --ignore=tests/test_vector_store.py --ignore=tests/test_connection.py --ignore=tests/test_chunking_strategies.py -q conf�� get --global ndor/bin/bash credential.helpebash(dns block)openaipublic.blob.core.windows.net/usr/bin/python python -m pytest tests/ -v --no-header -x --ignore=tests/test_integration.py --ignore=tests/test_graph_store.py --ignore=tests/test_vector_store.py --ignore=tests/test_connection.py git clon�� -b copilot/order-entity-extraction-process sh --depth 2 REDACTED git(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
Created from VS Code.
📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.