-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support edges to/from nested fields #149
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ def assert_ids_any_order( | |
assert set(result_ids) == set(expected), "should contain exactly expected IDs" | ||
|
||
|
||
@dataclass | ||
@dataclass(kw_only=True) | ||
class AdapterComplianceCase(abc.ABC): | ||
""" | ||
Base dataclass for test cases. | ||
|
@@ -56,6 +56,7 @@ class AdapterComplianceCase(abc.ABC): | |
|
||
id: str | ||
expected: list[str] | ||
requires_nested: bool = False | ||
|
||
|
||
@dataclass | ||
|
@@ -261,6 +262,46 @@ class AdjacentCase(AdapterComplianceCase): | |
"komodo dragon", # reptile | ||
], | ||
), | ||
AdjacentCase( | ||
id="nested", | ||
query="domesticated hunters", | ||
edges={ | ||
MetadataEdge("nested.a", 5), | ||
}, | ||
expected=[ | ||
"alligator", | ||
"alpaca", | ||
], | ||
requires_nested=True, | ||
), | ||
AdjacentCase( | ||
id="nested_same_field", | ||
query="domesticated hunters", | ||
edges={ | ||
MetadataEdge("nested.a", 5), | ||
MetadataEdge("nested.a", 6), | ||
}, | ||
expected=[ | ||
"alligator", | ||
"alpaca", | ||
"ant", | ||
], | ||
requires_nested=True, | ||
), | ||
AdjacentCase( | ||
id="nested_diff_field", | ||
query="domesticated hunters", | ||
edges={ | ||
MetadataEdge("nested.a", 5), | ||
MetadataEdge("nested.b", 5), | ||
}, | ||
expected=[ | ||
"alligator", | ||
"alpaca", | ||
"anteater", | ||
], | ||
requires_nested=True, | ||
), | ||
] | ||
|
||
|
||
|
@@ -273,6 +314,10 @@ class AdapterComplianceSuite(abc.ABC): | |
loaded. | ||
""" | ||
|
||
def supports_nested_metadata(self) -> bool: | ||
"""Return whether nested metadata is expected to work.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add some ability to create "features" that disable respective tests. Can refine later. |
||
return True | ||
|
||
def expected(self, method: str, case: AdapterComplianceCase) -> list[str]: | ||
""" | ||
Override to change the expected behavior of a case. | ||
|
@@ -299,6 +344,8 @@ def expected(self, method: str, case: AdapterComplianceCase) -> list[str]: | |
: | ||
The expected animals. | ||
""" | ||
if not self.supports_nested_metadata() and case.requires_nested: | ||
pytest.xfail("nested metadata not supported") | ||
return case.expected | ||
|
||
@pytest.fixture(params=GET_CASES, ids=lambda c: c.id) | ||
|
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
|
||
|
||
class TestChroma(AdapterComplianceSuite): | ||
def supports_nested_metadata(self) -> bool: | ||
return False | ||
|
||
@pytest.fixture(scope="class") | ||
def adapter( | ||
self, | ||
|
@@ -25,6 +28,16 @@ def adapter( | |
) | ||
|
||
shredder = ShreddingTransformer() | ||
|
||
# Chroma doesn't even support *writing* nested data currently, so we | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ugh. Chroma won't even persist things with nested data. |
||
# filter it out. | ||
def remove_nested_metadata(doc: Document) -> Document: | ||
metadata = doc.metadata.copy() | ||
metadata.pop("nested", None) | ||
return Document(id=doc.id, page_content=doc.page_content, metadata=metadata) | ||
|
||
animal_docs = [remove_nested_metadata(doc) for doc in animal_docs] | ||
|
||
docs = list(shredder.transform_documents(animal_docs)) | ||
store = Chroma.from_documents( | ||
docs, | ||
|
This file contains 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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Split keys on
.
. This is questionable -- some people might puta.b
in the key.