Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 29 additions & 9 deletions src/serverless/collections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,47 @@ use std::collections::HashSet;
use std::sync::Mutex;

use anyhow::{Context, Result, bail};
use qdrant_client::serverless::{CollectionConfig, CollectionSummary, QdrantServerless};
use qdrant_client::serverless::{
CollectionConfig, CollectionSummary, ListCollectionsBuilder, QdrantServerless,
};
use tokio::sync::Mutex as AsyncMutex;

/// Name of the `i`-th collection under `prefix` (`benchmark-` + `0` → `benchmark-0`).
pub fn collection_name(prefix: &str, index: usize) -> String {
format!("{prefix}{index}")
}

/// Largest page the serverless `ListCollections` API allows.
const LIST_PAGE_SIZE: u32 = 100;

/// All collections currently in the space whose name starts with `prefix`,
/// sorted by name.
/// sorted by name. Walks every page of the paginated listing.
pub async fn list_matching(
client: &QdrantServerless,
prefix: &str,
) -> Result<Vec<CollectionSummary>> {
let mut summaries: Vec<CollectionSummary> = client
.list_collections()
.await
.context("list_collections")?
.into_iter()
.filter(|c| c.collection_name.starts_with(prefix))
.collect();
let mut summaries: Vec<CollectionSummary> = Vec::new();
let mut offset_token: Option<String> = None;
loop {
let mut request = ListCollectionsBuilder::new().limit(LIST_PAGE_SIZE);
if let Some(token) = offset_token.take() {
request = request.offset_token(token);
}
let page = client
.list_collections(request)
.await
.context("list_collections")?;
summaries.extend(
page.collections
.into_iter()
.filter(|c| c.collection_name.starts_with(prefix)),
);
match page.next_offset_token {
// Guard against a server that echoes an empty token for "no more pages".
Some(token) if !token.is_empty() => offset_token = Some(token),
_ => break,
}
}
summaries.sort_by(|a, b| a.collection_name.cmp(&b.collection_name));
Ok(summaries)
}
Expand Down
34 changes: 33 additions & 1 deletion src/serverless/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,13 @@ pub fn to_serverless_config(upload: &UploadConfig) -> Result<CollectionConfig> {
continue;
}
let index: PayloadIndex = match field.kind {
PayloadType::Keyword => KeywordIndex.into(),
PayloadType::Keyword => {
let mut keyword = KeywordIndex::new();
if field.prefix {
keyword = keyword.with_prefix();
}
keyword.into()
}
PayloadType::Integer => IntegerIndex::new()
.lookup(true)
.range(field.range_index)
Expand Down Expand Up @@ -109,4 +115,30 @@ collection:
assert_eq!(cfg.dense_vectors[""].size, 128);
assert!(cfg.payload_indexes.contains_key("color"));
}

#[test]
fn keyword_prefix_flag_is_forwarded() {
let yaml = r#"
collection:
vectors:
- size: 4
distance: dot
fields:
- name: plain
type: keyword
- name: prefixed
type: keyword
prefix: true
"#;
let upload = crate::config::parse(yaml, "test").unwrap();
let cfg = to_serverless_config(&upload).unwrap();
match &cfg.payload_indexes["plain"] {
PayloadIndex::Keyword(k) => assert!(k.prefix.is_none()),
other => panic!("expected keyword index, got {other:?}"),
}
match &cfg.payload_indexes["prefixed"] {
PayloadIndex::Keyword(k) => assert!(k.prefix.is_some()),
other => panic!("expected keyword index, got {other:?}"),
}
}
}
Loading