-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENH] Fetch posting list operator (#3214)
## Description of changes *Summarize the changes made by this PR.* - Improvements & Bug fixes - Operator for fetching the posting list for a given head. Currently clones the posting list. Can revisit in future if it ends up becoming a performance bottleneck. - New functionality - ... ## Test plan *How are these changes tested?* - [x] Tests pass locally with `pytest` for python, `yarn test` for js, `cargo test` for rust ## Documentation Changes None
- Loading branch information
1 parent
adfd60f
commit 37a6103
Showing
4 changed files
with
147 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
use chroma_error::{ChromaError, ErrorCodes}; | ||
use chroma_index::spann::types::SpannPosting; | ||
use thiserror::Error; | ||
use tonic::async_trait; | ||
|
||
use crate::{ | ||
execution::operator::{Operator, OperatorType}, | ||
segment::spann_segment::{SpannSegmentReader, SpannSegmentReaderContext}, | ||
}; | ||
|
||
#[derive(Debug)] | ||
pub struct SpannFetchPlInput { | ||
// TODO(Sanket): Ship the reader instead of constructing here. | ||
reader_context: SpannSegmentReaderContext, | ||
head_id: u32, | ||
} | ||
|
||
#[allow(dead_code)] | ||
#[derive(Debug)] | ||
pub struct SpannFetchPlOutput { | ||
posting_list: Vec<SpannPosting>, | ||
} | ||
|
||
#[derive(Error, Debug)] | ||
pub enum SpannFetchPlError { | ||
#[error("Error creating spann segment reader")] | ||
SpannSegmentReaderCreationError, | ||
#[error("Error querying reader")] | ||
SpannSegmentReaderError, | ||
} | ||
|
||
impl ChromaError for SpannFetchPlError { | ||
fn code(&self) -> ErrorCodes { | ||
match self { | ||
Self::SpannSegmentReaderCreationError => ErrorCodes::Internal, | ||
Self::SpannSegmentReaderError => ErrorCodes::Internal, | ||
} | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct SpannFetchPlOperator {} | ||
|
||
impl SpannFetchPlOperator { | ||
#[allow(dead_code)] | ||
pub fn new() -> Box<Self> { | ||
Box::new(SpannFetchPlOperator {}) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl Operator<SpannFetchPlInput, SpannFetchPlOutput> for SpannFetchPlOperator { | ||
type Error = SpannFetchPlError; | ||
|
||
async fn run( | ||
&self, | ||
input: &SpannFetchPlInput, | ||
) -> Result<SpannFetchPlOutput, SpannFetchPlError> { | ||
let spann_reader = SpannSegmentReader::from_segment( | ||
&input.reader_context.segment, | ||
&input.reader_context.blockfile_provider, | ||
&input.reader_context.hnsw_provider, | ||
input.reader_context.dimension, | ||
) | ||
.await | ||
.map_err(|_| SpannFetchPlError::SpannSegmentReaderCreationError)?; | ||
let posting_list = spann_reader | ||
.fetch_posting_list(input.head_id) | ||
.await | ||
.map_err(|_| SpannFetchPlError::SpannSegmentReaderError)?; | ||
Ok(SpannFetchPlOutput { posting_list }) | ||
} | ||
|
||
// This operator is IO bound. | ||
fn get_type(&self) -> OperatorType { | ||
OperatorType::IO | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters