Skip to content

Commit b598d71

Browse files
committed
Rough out Vectorize Beta API
1 parent bd2a034 commit b598d71

File tree

5 files changed

+368
-0
lines changed

5 files changed

+368
-0
lines changed

worker-sys/src/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ mod r2;
1414
mod schedule;
1515
mod socket;
1616
mod tls_client_auth;
17+
mod vectorize;
1718
mod version;
1819
mod websocket_pair;
1920

@@ -33,5 +34,6 @@ pub use r2::*;
3334
pub use schedule::*;
3435
pub use socket::*;
3536
pub use tls_client_auth::*;
37+
pub use vectorize::*;
3638
pub use version::*;
3739
pub use websocket_pair::*;

worker-sys/src/types/vectorize.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use wasm_bindgen::prelude::*;
2+
3+
#[wasm_bindgen]
4+
extern "C" {
5+
#[wasm_bindgen(extends=js_sys::Object)]
6+
#[derive(Debug, Clone, PartialEq, Eq)]
7+
pub type VectorizeIndex;
8+
9+
#[wasm_bindgen(method, catch)]
10+
pub fn insert(
11+
this: &VectorizeIndex,
12+
vectors: js_sys::Object,
13+
) -> Result<js_sys::Promise, JsValue>;
14+
15+
#[wasm_bindgen(method, catch)]
16+
pub fn upsert(
17+
this: &VectorizeIndex,
18+
vectors: js_sys::Object,
19+
) -> Result<js_sys::Promise, JsValue>;
20+
21+
#[wasm_bindgen(method, catch)]
22+
pub fn describe(this: &VectorizeIndex) -> Result<js_sys::Promise, JsValue>;
23+
24+
#[wasm_bindgen(method, catch)]
25+
pub fn query(
26+
this: &VectorizeIndex,
27+
vector: &[f32],
28+
options: js_sys::Object,
29+
) -> Result<js_sys::Promise, JsValue>;
30+
31+
#[wasm_bindgen(method, catch, js_name = "getByIds")]
32+
pub fn get_by_ids(this: &VectorizeIndex, ids: JsValue) -> Result<js_sys::Promise, JsValue>;
33+
34+
#[wasm_bindgen(method, catch, js_name = "deleteByIds")]
35+
pub fn delete_by_ids(this: &VectorizeIndex, ids: JsValue) -> Result<js_sys::Promise, JsValue>;
36+
}

worker/src/env.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::fmt::Display;
44
use crate::d1::D1Database;
55
#[cfg(feature = "queue")]
66
use crate::Queue;
7+
use crate::VectorizeIndex;
78
use crate::{durable::ObjectNamespace, Bucket, DynamicDispatcher, Fetcher, Result};
89
use crate::{error::Error, hyperdrive::Hyperdrive};
910

@@ -89,6 +90,10 @@ impl Env {
8990
pub fn hyperdrive(&self, binding: &str) -> Result<Hyperdrive> {
9091
self.get_binding(binding)
9192
}
93+
94+
pub fn vectorize(&self, binding: &str) -> Result<VectorizeIndex> {
95+
self.get_binding(binding)
96+
}
9297
}
9398

9499
pub trait EnvBinding: Sized + JsCast {

worker/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ pub use crate::router::{RouteContext, RouteParams, Router};
190190
pub use crate::schedule::*;
191191
pub use crate::socket::*;
192192
pub use crate::streams::*;
193+
pub use crate::vectorize::*;
193194
pub use crate::version::*;
194195
pub use crate::websocket::*;
195196

@@ -226,6 +227,7 @@ mod schedule;
226227
pub mod send;
227228
mod socket;
228229
mod streams;
230+
mod vectorize;
229231
mod version;
230232
mod websocket;
231233

0 commit comments

Comments
 (0)