Repository navigation
unstructured2graph: GLiNER2Backend uses extract_long(), not extract() (#336) - #338
Merged
Merged
Conversation
…#336) extract() is a single forward pass with no windowing, and GLiNER2 has a fixed effective context. A session's combined text (one document per session since #331) routinely exceeds it, and past that point extract() both slows down and silently drops most entities, with no error. Measured on a real 16k-char session: extract() took 16.0s and found 18 entities; extract_long() (chunk_size=384, chunk_overlap=64, GLiNER2's own defaults) took 4.3s and found 249. Verified extract_long()'s output shape is identical to extract()'s, so this is a drop-in swap in _extract_sync. chunk_size/chunk_overlap are now GLiNER2Backend constructor parameters.
This was referenced Sep 16, 2026
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.
Summary
Fixes #336:
GLiNER2Backend._extract_synccalledmodel.extract()-- a single forward pass with no windowing. GLiNER2 is an encoder-only span/boundary classifier with a fixed effective context, and a session's combined text (one document per session since #331) routinely exceeds it. Past that pointextract()both slows down and silently drops most entities, with no error.model.extract_long(text, schema, chunk_size=..., chunk_overlap=..., ...)-- GLiNER2's own purpose-built API for this, windowing the text with overlap and merging results back into document-global coordinates.chunk_size/chunk_overlapare nowGLiNER2Backendconstructor parameters (defaulting to GLiNER2's own 384/64), alongside the existingentity_confidence_threshold/relation_confidence_thresholdknobs.Measured
Real session text pulled from the dedicated eval instance -- 16,280 chars, 12 turns. Model:
fastino/gliner2.5-base-v1, packagegliner2==2.0.0.model.extract(text, schema, ...)(before)model.extract_long(text, schema, chunk_size=384, chunk_overlap=64, ...)(after)3.7x faster and ~13.8x more entities recovered -- not a tradeoff. Verified
extract_long's return shape is identical toextract's (entities+relation_extractionkeys, same structure, span offsets correctly merged to global coordinates), so_extract_sync's existing parsing logic needed no change beyond the one call site.Test plan
ruff check/ruff format --checkcleanty checkclean (pre-existingty: ignore[unresolved-import]unused-locally warning, expected:gliner2isn't installed in CI, only in a local venv with it manually installed -- see the module's own docstring)gliner2/Memgraph needed): 14 passed, including two new regression tests --chunk_size/chunk_overlapdefault to GLiNER2's own values and are configurable, andextract_long()(notextract()) is called with the configured valuestest_e2e_gliner2.py, realgliner2==2.0.0+ live Memgraph): 2 passed -- confirms no regression on short textunstructured2graphsuite: 102 passed, 7 skipped (OPENAI_API_KEY-gated LightRAG e2e tests, unrelated to this change)