[ENH] Add python & js client support to query on subset of IDs
Description of changes
This PR adds python client and async python client support to query on a filtered set of IDs
example:
ids = ["1", "2", "3"]
documents = ["test", "test2", "apple"]
metadatas = [{"source": "test"}, {"source": "test2"}, {"source": "apple"}]
coll.add(
ids=ids,
documents=documents,
metadatas=metadatas,
# embeddings=numpy_embeddings
)
output = coll.query(
ids=["1", "3"],
query_texts=["test"],
n_results=3,
include=["documents", "metadatas", "distances"]
)
print(output)
This will output % python test_filter_id.py {'ids': [['1', '3']], 'embeddings': None, 'documents': [['test', 'apple']], 'uris': None, 'included': ['documents', 'metadatas', 'distances'], 'data': None, 'metadatas': [[{'source': 'test'}, {'source': 'apple'}]], 'distances': [[0.0, 0.7396076321601868]]}
Test plan
How are these changes tested?
- [x] Tests pass locally with
pytestfor python,yarn testfor js,cargo testfor rust - Added prop tests to test with other filtering and on its own
Documentation Changes
Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?
Reviewer Checklist
Please leverage this checklist to ensure your code review is thorough before approving
Testing, Bugs, Errors, Logs, Documentation
- [ ] Can you think of any use case in which the code does not behave as intended? Have they been tested?
- [ ] Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
- [ ] If appropriate, are there adequate property based tests?
- [ ] If appropriate, are there adequate unit tests?
- [ ] Should any logging, debugging, tracing information be added or removed?
- [ ] Are error messages user-friendly?
- [ ] Have all documentation changes needed been made?
- [ ] Have all non-obvious changes been commented?
System Compatibility
- [ ] Are there any potential impacts on other parts of the system or backward compatibility?
- [ ] Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?
Quality
- [ ] Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)
-
#4250
👈 (View in Graphite)
-
#4235
-
#4204
-
main
This stack of pull requests is managed by Graphite. Learn more about stacking.
i think i'm missing something, so for my edification, which part of the code actually processes the ids filter? Is it in here? https://github.com/hesreallyhim/chroma/blob/cac7f29be72907e71640981e7cf0dc94c68d06ce/rust/frontend/src/impls/in_memory_frontend.rs#L609
EDIT: Sorry that might be a really broad question, I don't know how the rust code works.
it would be cool to add filter syntax to ids, like {"$and": [{"$gt": 1000}, {"$lt": 2000}]} but i think it doesn't really make sense since we don't allow comparison like that for strings anyway, and IDs are strings...
@jairad26 would it be helpful for me to put together a PR to add this feature to the docs?
i think i'm missing something, so for my edification, which part of the code actually processes the
idsfilter? Is it in here? https://github.com/hesreallyhim/chroma/blob/cac7f29be72907e71640981e7cf0dc94c68d06ce/rust/frontend/src/impls/in_memory_frontend.rs#L609EDIT: Sorry that might be a really broad question, I don't know how the rust code works.
yep that's exactly the spot! all that does is filter by ids pre-vector search.
it would be cool to add filter syntax to ids, like {"$and": [{"$gt": 1000}, {"$lt": 2000}]} but i think it doesn't really make sense since we don't allow comparison like that for strings anyway, and IDs are strings...
yes that would be nice, but would only really work if the ids are ints. not 100% sure but i dont think uuids for example guarantee order like that. also random string generator definitely wouldn't work with that
@jairad26 would it be helpful for me to put together a PR to add this feature to the docs?
I'm moving this PR to draft for now, since i want to add support for the js client and that requires a couple other PRs to get merged. after that I can prob handle the docs. Thank you though!