Skip to content
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

Directly evaluating a MetadataFilters instance on a BaseNode instance #17580

Open
ZmeiGorynych opened this issue Jan 22, 2025 · 3 comments
Open

Comments

@ZmeiGorynych
Copy link
Contributor

Discussed in #17574

Originally posted by ZmeiGorynych January 21, 2025
Hi,
I have an instance of MetadataFilters and a List[BaseNode] and would like to select those nodes from that list that fit the filter. Is there already a function to do that? I'd think there would be a def MetadataFilters.matches(node: BaseNode) -> bool method, but haven't been able to find anything like that.
Reluctant to write my own as it'd have to support arbitrarily deep nested filters, etc.

Dosubot thinks there is no ready-made function for that and I have to write my own. Shall I contribute a method to the MetadataFilters class that does it?

Copy link

dosubot bot commented Jan 22, 2025

I found a similar discussion titled "Directly evaluating a MetadataFilters instance on a BaseNode instance" which is still open. The discussion revolves around the need for a method to filter a list of BaseNode instances using an instance of MetadataFilters. A bot response in the discussion suggests that there is a utility function named filter_nodes that can accomplish this task by iterating through the nodes and checking if their metadata matches the filters defined in MetadataFilters, returning the matching nodes [1].

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

@ZmeiGorynych
Copy link
Contributor Author

@dosu The function you quote is just a toy implementation from a tutorial, it doesn't handle nested AND and OR filters of arbitrary depth.

Copy link

dosubot bot commented Jan 22, 2025

The MetadataFilters class itself supports nested AND and OR filters of arbitrary depth, as demonstrated by test cases like test_milvus_filter_with_nested_filters [1]. However, the filter_nodes utility function's implementation details and its ability to handle such nested filters are not clearly documented in the available information. If the current implementation does not meet your needs, you might consider extending it or contributing a method to the MetadataFilters class that can evaluate filters directly on BaseNode instances.

To continue talking to Dosu, mention @dosu.


Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant