-
Notifications
You must be signed in to change notification settings - Fork 2k
[ENH] Add eventual consistency to the frontend #5946
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
base: main
Are you sure you want to change the base?
Changes from 6 commits
613cb67
23088ec
b2971be
691f8b1
c516e91
b8dae44
a26d674
81c6450
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ use crate::operators_generated::{ | |
| FUNCTION_STATISTICS_NAME, | ||
| }; | ||
| use crate::plan::PlanToProtoError; | ||
| use crate::plan::ReadLevel; | ||
| use crate::plan::SearchPayload; | ||
| use crate::validators::{ | ||
| validate_metadata_vec, validate_name, validate_non_empty_collection_update_metadata, | ||
|
|
@@ -2152,6 +2153,10 @@ impl From<(KnnBatchResult, IncludeList)> for QueryResponse { | |
| #[cfg_attr(feature = "utoipa", derive(utoipa::ToSchema))] | ||
| pub struct SearchRequestPayload { | ||
| pub searches: Vec<SearchPayload>, | ||
| /// Specifies the read level for consistency vs performance tradeoffs. | ||
| /// Defaults to IndexAndWal (full consistency). | ||
| #[serde(default)] | ||
| pub read_level: ReadLevel, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thoughts on having this per
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did consider this. I kind of prefer it to be homogenous. Reason is that if you are making decisions off this data, you want a consistent read across all the queries. |
||
| } | ||
|
|
||
| #[non_exhaustive] | ||
|
|
@@ -2163,6 +2168,8 @@ pub struct SearchRequest { | |
| pub collection_id: CollectionUuid, | ||
| #[validate(nested)] | ||
| pub searches: Vec<SearchPayload>, | ||
| /// Specifies the read level for consistency vs performance tradeoffs. | ||
| pub read_level: ReadLevel, | ||
| } | ||
|
|
||
| impl SearchRequest { | ||
|
|
@@ -2171,12 +2178,14 @@ impl SearchRequest { | |
| database_name: String, | ||
| collection_id: CollectionUuid, | ||
| searches: Vec<SearchPayload>, | ||
| read_level: ReadLevel, | ||
| ) -> Result<Self, ChromaValidationError> { | ||
| let request = Self { | ||
| tenant_id, | ||
| database_name, | ||
| collection_id, | ||
| searches, | ||
| read_level, | ||
| }; | ||
| request.validate().map_err(ChromaValidationError::from)?; | ||
| Ok(request) | ||
|
|
@@ -2185,6 +2194,7 @@ impl SearchRequest { | |
| pub fn into_payload(self) -> SearchRequestPayload { | ||
| SearchRequestPayload { | ||
| searches: self.searches, | ||
| read_level: self.read_level, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,8 +12,8 @@ use chroma_system::{ | |
| OrchestratorContext, PanicError, TaskError, TaskMessage, TaskResult, | ||
| }; | ||
| use chroma_types::{ | ||
| operator::Filter, CollectionAndSegments, HnswParametersFromSegmentError, SchemaError, | ||
| SegmentType, | ||
| operator::Filter, plan::ReadLevel, CollectionAndSegments, HnswParametersFromSegmentError, | ||
| SchemaError, SegmentType, | ||
| }; | ||
| use opentelemetry::trace::TraceContextExt; | ||
| use thiserror::Error; | ||
|
|
@@ -178,6 +178,9 @@ pub struct KnnFilterOrchestrator { | |
| // Fetched logs | ||
| fetched_logs: Option<FetchLogOutput>, | ||
|
|
||
| // Read level for consistency vs performance tradeoff | ||
| read_level: ReadLevel, | ||
|
|
||
| // Pipelined operators | ||
| filter: Filter, | ||
|
|
||
|
|
@@ -186,6 +189,7 @@ pub struct KnnFilterOrchestrator { | |
| } | ||
|
|
||
| impl KnnFilterOrchestrator { | ||
| #[allow(clippy::too_many_arguments)] | ||
| pub fn new( | ||
| blockfile_provider: BlockfileProvider, | ||
| dispatcher: ComponentHandle<Dispatcher>, | ||
|
|
@@ -194,6 +198,7 @@ impl KnnFilterOrchestrator { | |
| collection_and_segments: CollectionAndSegments, | ||
| fetch_log: FetchLogOperator, | ||
| filter: Filter, | ||
| read_level: ReadLevel, | ||
| ) -> Self { | ||
| let context = OrchestratorContext::new(dispatcher); | ||
| Self { | ||
|
|
@@ -204,10 +209,29 @@ impl KnnFilterOrchestrator { | |
| collection_and_segments, | ||
| fetch_log, | ||
| fetched_logs: None, | ||
| read_level, | ||
| filter, | ||
| result_channel: None, | ||
| } | ||
| } | ||
|
|
||
| fn create_filter_task( | ||
| &self, | ||
| logs: FetchLogOutput, | ||
| ctx: &ComponentContext<Self>, | ||
| ) -> TaskMessage { | ||
| wrap( | ||
| Box::new(self.filter.clone()), | ||
| FilterInput { | ||
| logs, | ||
| blockfile_provider: self.blockfile_provider.clone(), | ||
| metadata_segment: self.collection_and_segments.metadata_segment.clone(), | ||
| record_segment: self.collection_and_segments.record_segment.clone(), | ||
| }, | ||
| ctx.receiver(), | ||
| self.context.task_cancellation_token.clone(), | ||
| ) | ||
| } | ||
| } | ||
|
|
||
| #[async_trait] | ||
|
|
@@ -272,14 +296,28 @@ impl Orchestrator for KnnFilterOrchestrator { | |
| Span::current().add_link(prefetch_span.context().span().span_context().clone()); | ||
| tasks.push((prefetch_metadata_task, Some(prefetch_span))); | ||
|
|
||
| // Fetch log task. | ||
| let fetch_log_task = wrap( | ||
| Box::new(self.fetch_log.clone()), | ||
| (), | ||
| ctx.receiver(), | ||
| self.context.task_cancellation_token.clone(), | ||
| ); | ||
| tasks.push((fetch_log_task, Some(Span::current()))); | ||
| match self.read_level { | ||
| ReadLevel::IndexOnly => { | ||
| // For IndexOnly queries, skip log fetching and use empty logs | ||
| tracing::info!("Skipping log fetch for IndexOnly read level"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Performance] Using Consider using Context for Agents |
||
| let empty_logs = FetchLogOutput::new(Vec::new().into()); | ||
| self.fetched_logs = Some(empty_logs.clone()); | ||
|
|
||
| // Immediately schedule the filter task with empty logs | ||
| let filter_task = self.create_filter_task(empty_logs, ctx); | ||
| tasks.push((filter_task, Some(Span::current()))); | ||
| } | ||
| ReadLevel::IndexAndWal => { | ||
| // Fetch log task for full consistency. | ||
| let fetch_log_task = wrap( | ||
| Box::new(self.fetch_log.clone()), | ||
| (), | ||
| ctx.receiver(), | ||
| self.context.task_cancellation_token.clone(), | ||
| ); | ||
| tasks.push((fetch_log_task, Some(Span::current()))); | ||
| } | ||
| } | ||
|
|
||
| tasks | ||
| } | ||
|
|
@@ -326,17 +364,7 @@ impl Handler<TaskResult<FetchLogOutput, FetchLogError>> for KnnFilterOrchestrato | |
|
|
||
| self.fetched_logs = Some(output.clone()); | ||
|
|
||
| let task = wrap( | ||
| Box::new(self.filter.clone()), | ||
| FilterInput { | ||
| logs: output, | ||
| blockfile_provider: self.blockfile_provider.clone(), | ||
| metadata_segment: self.collection_and_segments.metadata_segment.clone(), | ||
| record_segment: self.collection_and_segments.record_segment.clone(), | ||
| }, | ||
| ctx.receiver(), | ||
| self.context.task_cancellation_token.clone(), | ||
| ); | ||
| let task = self.create_filter_task(output, ctx); | ||
| self.send(task, ctx, Some(Span::current())).await; | ||
| } | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.