Skip to content

Commit ca41a86

Browse files
committed
Refactor according to Vectorize V2 spec
1 parent b598d71 commit ca41a86

File tree

1 file changed

+20
-24
lines changed

1 file changed

+20
-24
lines changed

worker/src/vectorize.rs

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -32,27 +32,18 @@ pub enum VectorizeIndexConfig {
3232
#[derive(Debug, Deserialize)]
3333
#[serde(rename_all = "camelCase")]
3434
/// Metadata about an existing index.
35-
///
36-
/// This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released.
3735
pub struct VectorizeIndexDetails {
38-
pub id: String,
3936
pub name: String,
4037
pub description: Option<String>,
4138
pub config: VectorizeIndexConfig,
42-
pub vectors_count: u64,
4339
}
4440

4541
#[derive(Debug, Deserialize)]
4642
#[serde(rename_all = "camelCase")]
4743
/// Results of an operation that performed a mutation on a set of vectors.
48-
/// Here, `ids` is a list of vectors that were successfully processed.
49-
///
50-
/// This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released.
51-
pub struct VectorizeVectorMutation {
52-
/// List of ids of vectors that were successfully processed.
53-
pub ids: Vec<String>,
54-
/// Total count of the number of processed vectors.
55-
pub count: u64,
44+
pub struct VectorizeVectorAsyncMutation {
45+
/// The unique identifier for the async mutation operation containing the changeset.
46+
pub mutation_id: String,
5647
}
5748

5849
#[derive(Debug, Serialize)]
@@ -90,7 +81,7 @@ impl<'a> VectorizeVector<'a> {
9081
}
9182
}
9283

93-
#[derive(Debug, Serialize)]
84+
#[derive(Debug, Default, Serialize)]
9485
#[serde(rename_all = "kebab-case")]
9586
/// Metadata return levels for a Vectorize query.
9687
pub enum VectorizeMetadataRetrievalLevel {
@@ -99,6 +90,7 @@ pub enum VectorizeMetadataRetrievalLevel {
9990
/// Return all metadata fields configured for indexing in the vector return set. This level of retrieval is "free" in that no additional overhead is incurred returning this data. However, note that indexed metadata is subject to truncation (especially for larger strings).
10091
Indexed,
10192
/// No indexed metadata will be returned.
93+
#[default]
10294
None,
10395
}
10496

@@ -120,13 +112,14 @@ type VectorizeVectorMetadataFilter =
120112
#[derive(Debug, Serialize)]
121113
#[serde(rename_all = "camelCase")]
122114
pub struct VectorizeQueryOptions {
123-
// Default 3, max 20
115+
// Default 5, max 100
124116
top_k: u8,
117+
/// Return vectors from the specified namespace. Default `none`.
125118
namespace: Option<String>,
126119
/// Return vector values. Default `false`.
127120
return_values: bool,
128-
/// Return vector metadata. Default `false`.
129-
return_metadata: bool,
121+
/// Return vector metadata. Default `None`.
122+
return_metadata: VectorizeMetadataRetrievalLevel,
130123
/// Default `none`.
131124
filter: Option<VectorizeVectorMetadataFilter>,
132125
}
@@ -151,7 +144,10 @@ impl VectorizeQueryOptions {
151144
self
152145
}
153146

154-
pub fn with_return_metadata(mut self, return_metadata: bool) -> Self {
147+
pub fn with_return_metadata(
148+
mut self,
149+
return_metadata: VectorizeMetadataRetrievalLevel,
150+
) -> Self {
155151
self.return_metadata = return_metadata;
156152
self
157153
}
@@ -173,10 +169,10 @@ impl VectorizeQueryOptions {
173169
impl Default for VectorizeQueryOptions {
174170
fn default() -> Self {
175171
Self {
176-
top_k: 3,
172+
top_k: 5,
177173
namespace: None,
178174
return_values: false,
179-
return_metadata: false,
175+
return_metadata: VectorizeMetadataRetrievalLevel::None,
180176
filter: None,
181177
}
182178
}
@@ -191,6 +187,8 @@ pub struct VectorizeVectorResult {
191187
pub values: Option<Vec<f32>>,
192188
/// Metadata associated with the vector. Includes the values of other fields and potentially additional details.
193189
pub metadata: Option<serde_json::Map<String, serde_json::Value>>,
190+
/** The namespace the vector belongs to. */
191+
pub namespace: Option<String>,
194192
}
195193

196194
#[derive(Debug, Deserialize)]
@@ -209,8 +207,6 @@ pub struct VectorizeMatches {
209207
}
210208

211209
/// A Vectorize Vector Search Index for querying vectors/embeddings.
212-
///
213-
/// This type is exclusively for the Vectorize **beta** and will be deprecated once Vectorize RC is released.
214210
pub struct VectorizeIndex(VectorizeIndexSys);
215211

216212
unsafe impl Send for VectorizeIndex {}
@@ -233,7 +229,7 @@ impl VectorizeIndex {
233229
pub async fn insert<'a>(
234230
&self,
235231
vectors: &[VectorizeVector<'a>],
236-
) -> Result<VectorizeVectorMutation> {
232+
) -> Result<VectorizeVectorAsyncMutation> {
237233
let promise = self
238234
.0
239235
.insert(serde_wasm_bindgen::to_value(&vectors)?.into())?;
@@ -246,7 +242,7 @@ impl VectorizeIndex {
246242
pub async fn upsert<'a>(
247243
&self,
248244
vectors: &[VectorizeVector<'a>],
249-
) -> Result<VectorizeVectorMutation> {
245+
) -> Result<VectorizeVectorAsyncMutation> {
250246
let promise = self
251247
.0
252248
.upsert(serde_wasm_bindgen::to_value(&vectors)?.into())?;
@@ -269,7 +265,7 @@ impl VectorizeIndex {
269265
}
270266

271267
/// Delete a list of vectors with a matching id.
272-
pub async fn delete_by_ids<'a, T>(&self, ids: T) -> Result<VectorizeVectorMutation>
268+
pub async fn delete_by_ids<'a, T>(&self, ids: T) -> Result<VectorizeVectorAsyncMutation>
273269
where
274270
T: IntoIterator<Item = &'a str>,
275271
{

0 commit comments

Comments
 (0)