#[cfg(any(feature = "rest", feature = "grpc"))]
use std::sync::atomic::{AtomicU64, Ordering};
#[cfg(any(feature = "rest", feature = "grpc"))]
use std::time::{SystemTime, UNIX_EPOCH};
use async_trait::async_trait;
use qql_core::error::QqlError;
use qql_plan::types::ReadConsistencyParam;
use qql_plan::{QueryBatchRequest, UpdateBatchRequest};
use crate::executor::response::BackendResponse;
pub use crate::backend::CollectionInfo;
pub const REQUEST_ID_HEADER: &str = "x-request-id";
#[cfg(any(feature = "rest", feature = "grpc"))]
static REQUEST_SEQ: AtomicU64 = AtomicU64::new(0);
#[cfg(any(feature = "rest", feature = "grpc"))]
pub(crate) fn next_request_id() -> String {
let seq = REQUEST_SEQ.fetch_add(1, Ordering::Relaxed);
let nanos = SystemTime::now()
.duration_since(UNIX_EPOCH)
.map(|d| d.as_nanos() as u64)
.unwrap_or(0);
format!("qql-{nanos:016x}{seq:04x}")
}
#[derive(Debug, Clone)]
pub struct VectorTopology {
pub dense_vector: Option<String>,
pub sparse_vector: Option<String>,
pub rerank_vector: Option<String>,
}
#[cfg(not(target_arch = "wasm32"))]
pub trait QdrantOpsBound: Send + Sync {}
#[cfg(not(target_arch = "wasm32"))]
impl<T: Send + Sync> QdrantOpsBound for T {}
#[cfg(target_arch = "wasm32")]
pub trait QdrantOpsBound {}
#[cfg(target_arch = "wasm32")]
impl<T> QdrantOpsBound for T {}
#[cfg_attr(target_arch = "wasm32", async_trait(?Send))]
#[cfg_attr(not(target_arch = "wasm32"), async_trait)]
pub trait QdrantOps: QdrantOpsBound {
async fn close(&self) -> Result<(), QqlError> {
Ok(())
}
async fn list_collections(&self) -> Result<Vec<String>, QqlError>;
async fn collection_exists(&self, name: &str) -> Result<bool, QqlError>;
async fn get_collection_info(&self, name: &str) -> Result<CollectionInfo, QqlError>;
async fn create_collection(
&self,
collection_name: &str,
req: &qql_plan::CreateCollectionRequest,
) -> Result<(), QqlError>;
async fn update_collection(
&self,
collection_name: &str,
req: &qql_plan::UpdateCollectionRequest,
) -> Result<(), QqlError>;
async fn delete_collection(&self, name: &str) -> Result<(), QqlError>;
async fn create_field_index(
&self,
collection_name: &str,
req: &qql_plan::CreateIndexRequest,
) -> Result<(), QqlError>;
async fn delete_field_index(
&self,
collection_name: &str,
field_name: &str,
) -> Result<(), QqlError>;
async fn execute_planned(
&self,
op: &qql_plan::PlannedOperation,
) -> Result<BackendResponse, QqlError>;
async fn execute_query_batch(
&self,
collection: &str,
batch: &QueryBatchRequest,
timeout: Option<u64>,
consistency: Option<ReadConsistencyParam>,
) -> Result<Vec<BackendResponse>, QqlError>;
async fn execute_update_batch(
&self,
collection: &str,
batch: &UpdateBatchRequest,
wait: bool,
) -> Result<Vec<BackendResponse>, QqlError>;
async fn change_aliases(&self, _actions: &[AliasAction]) -> Result<(), QqlError> {
Err(QqlError::validation(
"QQL-VALIDATION-ALIASES",
"collection aliases are not supported on this backend",
None,
))
}
async fn optimize_collection(&self, _collection: &str) -> Result<bool, QqlError> {
Err(QqlError::validation(
"QQL-BACKEND-OPTIMIZE",
"optimize is not supported by this backend",
None,
))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AliasAction {
Delete {
alias: String,
},
Create {
collection: String,
alias: String,
},
}