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

[ENH] [PERF] add indices to metadata columns #2623

Merged
merged 3 commits into from
Aug 19, 2024
Merged

Conversation

levand
Copy link
Contributor

@levand levand commented Aug 2, 2024

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:

image image

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:

image

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

  • Unit and property tests pass in CI

Documentation Changes

  • None required

Copy link

github-actions bot commented Aug 2, 2024

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)

Copy link

github-actions bot commented Aug 2, 2024

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

Copy link

github-actions bot commented Aug 2, 2024

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

@levand levand changed the title Add indexes to metadata columns PERF: add indexes to metadata columns Aug 2, 2024
@levand levand changed the title PERF: add indexes to metadata columns PERF: add indices to metadata columns Aug 2, 2024
@levand levand marked this pull request as ready for review August 2, 2024 19:42
@levand levand requested a review from atroyn August 12, 2024 16:34
@atroyn
Copy link
Contributor

atroyn commented Aug 12, 2024

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?

@atroyn atroyn changed the title PERF: add indices to metadata columns [ENH] [PERF]: add indices to metadata columns Aug 12, 2024
Copy link

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

Copy link

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

@levand levand changed the title [ENH] [PERF]: add indices to metadata columns [ENH] add indices to metadata columns Aug 15, 2024
Copy link

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

@levand levand changed the title [ENH] add indices to metadata columns [ENH] [PERF] add indices to metadata columns Aug 15, 2024
@levand levand merged commit 267f7bb into main Aug 19, 2024
67 checks passed
@jeffchuber jeffchuber mentioned this pull request Sep 15, 2024
1 task
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

Successfully merging this pull request may close these issues.

3 participants