Skip to content

Commit

Permalink
Added new tests to improve test coverage for Neo4jVector (#17)
Browse files Browse the repository at this point in the history
  • Loading branch information
willtai authored Dec 4, 2024
1 parent 92f590b commit 7b6f4ef
Show file tree
Hide file tree
Showing 5 changed files with 909 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ __pycache__
.idea
.vscode
**/.DS_Store
.coverage
14 changes: 7 additions & 7 deletions libs/neo4j/langchain_neo4j/vectorstores/neo4j_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ def _handle_field_filter(
query_snippet = f"toLower(n.`{field}`) CONTAINS $param_{param_number}"
query_param = {f"param_{param_number}": filter_value.rstrip("%")}
return (query_snippet, query_param)
else:
raise NotImplementedError()
else:
raise NotImplementedError()

raise NotImplementedError("Unhandled operator")


def construct_metadata_filter(filter: Dict[str, Any]) -> Tuple[str, Dict]:
"""Construct a metadata filter.
Expand Down Expand Up @@ -386,7 +386,7 @@ def construct_metadata_filter(filter: Dict[str, Any]) -> Tuple[str, Dict]:
and_ = combine_queries(
[construct_metadata_filter(el) for el in value], "AND"
)
if len(and_) >= 1:
if len(and_[0]) >= 1:
return and_
else:
raise ValueError(
Expand All @@ -397,7 +397,7 @@ def construct_metadata_filter(filter: Dict[str, Any]) -> Tuple[str, Dict]:
or_ = combine_queries(
[construct_metadata_filter(el) for el in value], "OR"
)
if len(or_) >= 1:
if len(or_[0]) >= 1:
return or_
else:
raise ValueError(
Expand All @@ -422,7 +422,7 @@ def construct_metadata_filter(filter: Dict[str, Any]) -> Tuple[str, Dict]:
for index, (k, v) in enumerate(filter.items())
]
)
if len(and_multiple) >= 1:
if len(and_multiple[0]) >= 1:
return " AND ".join(and_multiple[0]), and_multiple[1]
else:
raise ValueError(
Expand Down Expand Up @@ -862,7 +862,7 @@ def __from(
embedding_dimension and not store.embedding_dimension == embedding_dimension
):
raise ValueError(
f"Index with name {store.index_name} already exists."
f"Index with name {store.index_name} already exists. "
"The provided embedding function and vector index "
"dimensions do not match.\n"
f"Embedding function dimension: {store.embedding_dimension}\n"
Expand Down Expand Up @@ -1539,7 +1539,7 @@ def from_existing_graph(
embedding_dimension and not store.embedding_dimension == embedding_dimension
):
raise ValueError(
f"Index with name {store.index_name} already exists."
f"Index with name {store.index_name} already exists. "
"The provided embedding function and vector index "
"dimensions do not match.\n"
f"Embedding function dimension: {store.embedding_dimension}\n"
Expand Down
97 changes: 96 additions & 1 deletion libs/neo4j/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion libs/neo4j/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pytest-asyncio = "^0.23.2"
pytest-socket = "^0.7.0"
pytest-watcher = "^0.3.4"
langchain-core = {git = "https://github.com/langchain-ai/langchain.git", subdirectory = "libs/core"}
pytest-cov = "^6.0.0"

[tool.poetry.group.codespell]
optional = true
Expand Down Expand Up @@ -82,7 +83,7 @@ build-backend = "poetry.core.masonry.api"
# section of the configuration file raise errors.
#
# https://github.com/tophat/syrupy
addopts = "--strict-markers --strict-config --durations=5"
addopts = "--strict-markers --strict-config --durations=5 --cov=langchain_neo4j --cov-report=html --cov-report=term"
# Registering custom markers.
# https://docs.pytest.org/en/7.1.x/example/markers.html#registering-markers
markers = [
Expand Down
Loading

0 comments on commit 7b6f4ef

Please sign in to comment.