Skip to content

Commit f2edd3e

Browse files
committed
feat(qdrant): Add vector index support
1 parent ac786d7 commit f2edd3e

File tree

5 files changed

+44
-10
lines changed

5 files changed

+44
-10
lines changed

docs/docs/targets/index.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,3 @@ You can find end-to-end examples fitting into any of supported property graphs i
333333
* <ExampleButton href="https://github.com/cocoindex-io/cocoindex/tree/main/examples/docs_to_knowledge_graph" text="Docs to Knowledge Graph" margin="0 0 16px 0" />
334334

335335
* <ExampleButton href="https://github.com/cocoindex-io/cocoindex/tree/main/examples/product_recommendation" text="Product Recommendation" margin="0 0 16px 0" />
336-
337-
338-

docs/docs/targets/kuzu.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Exports data to a [Kuzu](https://kuzu.com/) graph database.
1111

1212
## Get Started
1313

14-
Read [Property Graph Targets](./index.md#property-graph-targets) for more information to get started on how it works in CocoIndex.
14+
Read [Property Graph Targets](./index.md#property-graph-targets) for more information to get started on how it works in CocoIndex.
1515

1616
## Spec
1717

@@ -57,4 +57,4 @@ You can then access the explorer at [http://localhost:8124](http://localhost:812
5757
href="https://github.com/cocoindex-io/cocoindex/tree/main/examples/docs_to_knowledge_graph"
5858
text="Docs to Knowledge Graph"
5959
margin="16px 0 24px 0"
60-
/>
60+
/>

docs/docs/targets/neo4j.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { ExampleButton } from '../../src/components/GitHubButton';
1111

1212

1313
## Get Started
14-
Read [Property Graph Targets](./index.md#property-graph-targets) for more information to get started on how it works in CocoIndex.
14+
Read [Property Graph Targets](./index.md#property-graph-targets) for more information to get started on how it works in CocoIndex.
1515

1616

1717
## Spec
@@ -49,4 +49,4 @@ You can access the Neo4j browser at [http://localhost:7474](http://localhost:747
4949
href="https://github.com/cocoindex-io/cocoindex/tree/main/examples/docs_to_knowledge_graph"
5050
text="Docs to Knowledge Graph"
5151
margin="16px 0 24px 0"
52-
/>
52+
/>

docs/sidebars.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ const sidebars: SidebarsConfig = {
4949
link: { type: 'doc', id: 'targets/index' },
5050
collapsed: true,
5151
items: [
52-
52+
5353
'targets/postgres',
5454
'targets/qdrant',
5555
'targets/lancedb',

src/ops/targets/qdrant.rs

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ struct VectorDef {
139139
metric: spec::VectorSimilarityMetric,
140140
#[serde(default, skip_serializing_if = "Option::is_none")]
141141
multi_vector_comparator: Option<String>,
142+
#[serde(default, skip_serializing_if = "Option::is_none")]
143+
method: Option<spec::VectorIndexMethod>,
142144
}
143145
#[derive(Debug, Clone, Serialize, Deserialize)]
144146
struct SetupState {
@@ -221,6 +223,26 @@ impl SetupChange {
221223
vector_def.vector_size as u64,
222224
embedding_metric_to_qdrant(vector_def.metric)?,
223225
);
226+
if let Some(method) = &vector_def.method {
227+
match method {
228+
spec::VectorIndexMethod::Hnsw { m, ef_construction } => {
229+
if let Some(m_val) = m {
230+
params = params.hnsw_m(*m_val as u64);
231+
}
232+
if let Some(ef_val) = ef_construction {
233+
params = params.hnsw_ef_construct(*ef_val as u64);
234+
}
235+
}
236+
spec::VectorIndexMethod::IvfFlat { nlist } => {
237+
if let Some(nlist_val) = nlist {
238+
params = params.ivf_flat_nlist(*nlist_val as u64);
239+
}
240+
}
241+
_ => {
242+
api_bail!("Unsupported vector index method for Qdrant");
243+
}
244+
}
245+
}
224246
if let Some(multi_vector_comparator) = &vector_def.multi_vector_comparator {
225247
params = params.multivector_config(MultiVectorConfigBuilder::new(
226248
MultiVectorComparator::from_str_name(multi_vector_comparator)
@@ -422,8 +444,23 @@ impl TargetFactoryBase for Factory {
422444
} else {
423445
api_bail!("Field `{}` specified more than once in vector index definition", vector_index.field_name);
424446
}
425-
if vector_index.method.is_some() {
426-
api_bail!("Vector index method is not configurable for Qdrant yet");
447+
448+
let vector_def_entry = vector_def.get_mut(&vector_index.field_name)
449+
.expect("VectorDef must exist here");
450+
451+
vector_def_entry.vector_size = vector_index.vector_size;
452+
vector_def_entry.metric = vector_index.metric.clone();
453+
454+
if let Some(method) = &vector_index.method {
455+
match method {
456+
spec::VectorIndexMethod::Hnsw { .. } |
457+
spec::VectorIndexMethod::IvfFlat { .. } => {
458+
vector_def_entry.method = Some(method.clone());
459+
}
460+
_ => {
461+
api_bail!("Vector index method is not supported for Qdrant");
462+
}
463+
}
427464
}
428465
}
429466
None => {

0 commit comments

Comments
 (0)