-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[ENH] [PERF] add indices to metadata columns #2623
Conversation
Reviewer ChecklistPlease leverage this checklist to ensure your code review is thorough before approving Testing, Bugs, Errors, Logs, Documentation
System Compatibility
Quality
|
Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas |
a1808c3
to
d0c486a
Compare
Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas |
I think we can eat the increased DB size for faster filtering. We also wouldn't expect indices to help where the returned set is large, but we should probably think about how we might speed this up further; is most of the remaining latency coming from the realization step? |
Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas |
Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas |
Please tag your PR title with one of: [ENH | BUG | DOC | TST | BLD | PERF | TYP | CLN | CHORE]. See https://docs.trychroma.com/contributing#contributing-code-and-ideas |
Description of changes
Add indexes to sqlite metadata value columns.
This greatly improves the performance of queries that filter based on equality or comparison to metadata fields:
Note that the index only improves performance when the filter is highly selective. If there are large numbers of records that match the filter, processing is still slow (as they must all realized in memory and passed to the vector search.)
Migration Plan
Creating the indexes on a database of ~40,000 embeddings with ~600,000 metadata rows takes less than ten seconds. It will seamlessly be applied to existing databases the first time they are loaded.
The change should be both forward and backward compatible. The only effect of the presence or absence of indices should be on the underlying sqlite query plan: result set semantics should be invariant according to SQL semantics.
Downsides
This change does have an small constant effect on insert speed:
It also yields somewhat larger sqlite database sizes: 1.7gb vs 1.5gb, for the scenario where each embedding has 15 metadata fields (5 ints, 5 floats, 5 strings of 1-10 words)
Test plan
Documentation Changes