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] full-text search index reader and writer #2178

Merged
merged 3 commits into from May 13, 2024
Merged

Conversation

beggers
Copy link
Member

@beggers beggers commented May 10, 2024

Description of changes

Summarize the changes made by this PR.

  • New functionality
    • Migrate the full-text search index to the new reader/writer pattern and add some tests.

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

Copy link

vercel bot commented May 10, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
chroma ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 13, 2024 9:10pm

Copy link

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)

async fn commit_and_flush(self) -> Result<(), Box<dyn ChromaError>> {
// TODO should we be `await?`ing these? Or can we just return the futures?
self.posting_lists_blockfile_writer
.commit::<u32, &Int32Array>()?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: we no longer store the positional posting list directly as a value, but rather as (token, doc_id) key and positions value. I think this is strictly better?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So
prefix: token
key: doc_id
positions: [pos]?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think thats fine, its functionally the same at storage. Can we remove the pos value type from storage then and only use it as a builder?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the fun part -- it's already not in Storage! If you're talking about in-memory storage at least

// for the character have been seen/used in the matching algorithm. By
// leaving them ordered per the query, we can stick to the more straightforward
// but less efficient matching algorithm.
// token_frequencies.sort_by(|a, b| a.1.cmp(&b.1));
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do the work to sort by token frequency now? It'll take some time to get it right and test. This bug was lurking in the old implementation (yet another argument for property testing).

}
}
Ok(())
}

fn search(&mut self, query: &str) -> Result<Vec<i32>, Box<dyn ChromaError>> {
async fn commit_and_flush(self) -> Result<(), Box<dyn ChromaError>> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want this method at the index level, if you look at the higher level pattern we want commit and flush as two steps with a type safe transition

}
if res.len() > 1 {
panic!("Multiple tokens found in frequencies blockfile");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no panic?

for position_for_doc_id in positions_for_doc_id.values() {
if position_for_doc_id - token_offset == *position {
for pos in positions.iter() {
if pos.unwrap() == position + token_offset {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this unwrap safe?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not it's an invariant violation. Changed to a Result

Copy link
Collaborator

@HammadB HammadB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall, some minor to moderate comments


#[derive(Error, Debug)]
pub enum FullTextIndexError {
#[error("Multiple tokens found in frequencies blockfile")]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this error? (just missing something)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The frequencies blockfile should have exactly zero or one entries for a given token. If it has multiple then something very bad has happened (constraint violation/data corruption)

}
}

pub(crate) struct FullTextIndexFlusher {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks

@beggers beggers merged commit a843309 into main May 13, 2024
46 checks passed
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.

None yet

2 participants