Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
2 changes: 1 addition & 1 deletion .github/workflows/pr-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.10', '3.13']
python-version: ['3.10', '3.14']
neo4j-tag:
- 'latest'
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.10', '3.11', '3.12', '3.13' ]
python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14' ]
steps:
- name: Free up disk space (ubuntu-latest)
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.9"
python-version: "3.10"
- name: Install pypa/build
run: >-
python3 -m
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/scheduled-e2e-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.10', '3.11', '3.12', '3.13']
python-version: [ '3.10', '3.11', '3.12', '3.13', '3.14']
neo4j-tag:
- 'community'
- 'enterprise'
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## Next

## Added

- Support for Python 3.14
- Support for version 6.0.0 of the Neo4j Python driver

### Changed

- Switched project/dependency management from Poetry to uv.
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,11 @@ A list of Neo4j GenAI-related features can also be found at [Neo4j GenAI Ecosyst

| Version | Supported? |
|---------|-----------:|
| 3.14 | ✓ |
| 3.13 | ✓ |
| 3.12 | ✓ |
| 3.11 | ✓ |
| 3.10 | ✓ |
| 3.9 | ✗ |
| 3.8 | ✗ |

## 📦 Installation

Expand Down Expand Up @@ -60,6 +59,10 @@ the extra dependencies described below:
- **pinecone**: store vectors in Pinecone
- **qdrant**: store vectors in Qdrant
- **experimental**: experimental features mainly related to the Knowledge Graph creation pipelines.
- **nlp**: installs spaCy for NLP pipelines, used by `SpaCySemanticMatchResolver` in the experimental KG builder components.
- **fuzzy-matching**: installs RapidFuzz, used by `FuzzyMatchResolver` in the experimental KG builder components.

> Note: The **`nlp`** extra is currently **not supported on Python 3.14** due to an upstream spaCy import-time issue ([spaCy #13895](https://github.com/explosion/spaCy/issues/13895)). Use Python **3.13 or earlier** for spaCy-based features until that is resolved upstream.


Install package with optional dependencies with (for instance):
Expand Down
5 changes: 5 additions & 0 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Neo4j versions supported:

Python versions supported:

* Python 3.14
* Python 3.13
* Python 3.12
* Python 3.11
Expand Down Expand Up @@ -101,6 +102,10 @@ List of extra dependencies:
- **nlp**: installs spaCy for nlp pipelines, used by `SpaCySemanticMatchResolver` component from the Knowledge Graph creation pipelines.
- **fuzzy-matching**: installs **rapidfuzz** to fuzzy matching using string similarity, used by `FuzzyMatchResolver` component from the Knowledge Graph creation pipelines.

.. note::

The **`nlp`** extra (spaCy) is currently **not supported on Python 3.14** due to an upstream spaCy import-time issue (see `spaCy #13895 <https://github.com/explosion/spaCy/issues/13895>`_). Use Python **3.13 or earlier** for spaCy-based features until that is resolved upstream.

********
Examples
********
Expand Down
13 changes: 8 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ authors = [
]
license = {text = "Apache License, Version 2.0"}
readme = "README.md"
requires-python = ">=3.10.0,<3.14"
requires-python = ">=3.10.0,<3.15"
dependencies = [
"neo4j>=5.17.0,<6.0.0",
"neo4j>=5.17.0,<7.0.0",
"pydantic>=2.6.3,<3.0.0",
"fsspec>=2024.9.0,<2025.0.0",
"pypdf>=6.0.0,<7.0.0",
"json-repair>=0.44.1,<0.45.0",
"pyyaml>=6.0.2,<7.0.0",
"types-pyyaml>=6.0.12.20240917,<7.0.0",
"numpy>=2.0.0,<3.0.0; python_version >= '3.9' and python_version < '3.13'",
"numpy>=2.1.0,<3.0.0; python_version >= '3.13' and python_version < '3.14'",
"numpy>=2.1.0,<3.0.0; python_version >= '3.13' and python_version < '3.15'",
"scipy>=1.13.0,<2.0.0; python_version >= '3.9' and python_version < '3.13'",
"scipy>=1.15.0,<2.0.0; python_version >= '3.13' and python_version < '3.14'",
"scipy>=1.15.0,<2.0.0; python_version >= '3.13' and python_version < '3.15'",
"tenacity>=9.1.2,<10.0.0",
]

Expand Down Expand Up @@ -63,7 +63,10 @@ examples = [
"langchain-openai>=0.2.2,<0.3.0",
"langchain-huggingface>=0.1.0,<0.2.0",
]
nlp = ["spacy==3.8.7"]
# NOTE: spaCy currently has a Python 3.14 import-time failure via its pydantic v1 path
# (see https://github.com/explosion/spaCy/issues/13895). Until upstream resolves this,
# only advertise/install the `nlp` extra on Python <3.14.
nlp = ["spacy==3.8.7; python_version < '3.14'"]
fuzzy-matching = ["rapidfuzz>=3.12.2,<4.0.0"]

[dependency-groups]
Expand Down
48 changes: 33 additions & 15 deletions src/neo4j_graphrag/experimental/components/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,8 @@

try:
import numpy as np
import spacy
from spacy.cli.download import download as spacy_download
from spacy.language import Language

IS_SPACY_INSTALLED = True
except ImportError:
IS_SPACY_INSTALLED = False
raise


if TYPE_CHECKING:
Expand All @@ -51,6 +46,30 @@
logger = logging.getLogger(__name__)


def _import_spacy() -> tuple[Any, Any]:
"""
Import spaCy lazily.

spaCy (via `confection`) currently imports `pydantic.v1`, which is not compatible
with Python 3.14 in some scenarios and can raise non-ImportError exceptions at
import time. Treat any such failure as "spaCy unavailable".

Upstream reference: https://github.com/explosion/spaCy/issues/13895
"""

try:
import spacy
from spacy.cli.download import download as spacy_download

return spacy, spacy_download
except Exception as e: # noqa: BLE001
raise ImportError(
"`spacy` python module needs to be installed (and importable) to use "
"the SpaCySemanticMatchResolver. Install it with: "
'`pip install "neo4j-graphrag[nlp]"`'
) from e


class EntityResolver(Component):
"""Entity resolution base class

Expand Down Expand Up @@ -353,21 +372,19 @@ def __init__(
auto_download_spacy_model: bool = True,
neo4j_database: Optional[str] = None,
) -> None:
if not IS_SPACY_INSTALLED:
raise ImportError("""`spacy` python module needs to be installed to use
the SpaCySemanticMatchResolver. Install it with:
`pip install "neo4j-graphrag[nlp]"`
""")
super().__init__(
driver,
filter_query,
resolve_properties,
similarity_threshold,
neo4j_database,
)
self.nlp = nlp or self._load_or_download_spacy_model(
spacy_model, auto_download_spacy_model=auto_download_spacy_model
)
if nlp is not None:
self.nlp = nlp
else:
self.nlp = self._load_or_download_spacy_model(
spacy_model, auto_download_spacy_model=auto_download_spacy_model
)
self.embedding_cache: dict[str, NDArray[np.float64]] = {}

async def run(self) -> ResolutionStats:
Expand Down Expand Up @@ -402,11 +419,12 @@ def _cosine_similarity(
@staticmethod
def _load_or_download_spacy_model(
model_name: str, *, auto_download_spacy_model: bool = True
) -> Language:
) -> Any:
"""
Attempt to load the specified spaCy model by name.
If not installed, automatically download and then load it.
"""
spacy, spacy_download = _import_spacy()
try:
return spacy.load(model_name)
except OSError as e:
Expand Down
2 changes: 1 addition & 1 deletion tox.ini
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[tox]
envlist = py39, py310, py311, py312
envlist = py310, py311, py312, py313, py314


[testenv]
Expand Down
Loading