Skip to content

Commit

Permalink
Rough out Vectorize Beta API
Browse files Browse the repository at this point in the history
  • Loading branch information
kflansburg committed Aug 2, 2024
1 parent bd2a034 commit b598d71
Show file tree
Hide file tree
Showing 5 changed files with 368 additions and 0 deletions.
2 changes: 2 additions & 0 deletions worker-sys/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod r2;
mod schedule;
mod socket;
mod tls_client_auth;
mod vectorize;
mod version;
mod websocket_pair;

Expand All @@ -33,5 +34,6 @@ pub use r2::*;
pub use schedule::*;
pub use socket::*;
pub use tls_client_auth::*;
pub use vectorize::*;
pub use version::*;
pub use websocket_pair::*;
36 changes: 36 additions & 0 deletions worker-sys/src/types/vectorize.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use wasm_bindgen::prelude::*;

#[wasm_bindgen]
extern "C" {
#[wasm_bindgen(extends=js_sys::Object)]
#[derive(Debug, Clone, PartialEq, Eq)]
pub type VectorizeIndex;

#[wasm_bindgen(method, catch)]
pub fn insert(
this: &VectorizeIndex,
vectors: js_sys::Object,
) -> Result<js_sys::Promise, JsValue>;

#[wasm_bindgen(method, catch)]
pub fn upsert(
this: &VectorizeIndex,
vectors: js_sys::Object,
) -> Result<js_sys::Promise, JsValue>;

#[wasm_bindgen(method, catch)]
pub fn describe(this: &VectorizeIndex) -> Result<js_sys::Promise, JsValue>;

#[wasm_bindgen(method, catch)]
pub fn query(
this: &VectorizeIndex,
vector: &[f32],
options: js_sys::Object,
) -> Result<js_sys::Promise, JsValue>;

#[wasm_bindgen(method, catch, js_name = "getByIds")]
pub fn get_by_ids(this: &VectorizeIndex, ids: JsValue) -> Result<js_sys::Promise, JsValue>;

#[wasm_bindgen(method, catch, js_name = "deleteByIds")]
pub fn delete_by_ids(this: &VectorizeIndex, ids: JsValue) -> Result<js_sys::Promise, JsValue>;
}
5 changes: 5 additions & 0 deletions worker/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt::Display;
use crate::d1::D1Database;
#[cfg(feature = "queue")]
use crate::Queue;
use crate::VectorizeIndex;
use crate::{durable::ObjectNamespace, Bucket, DynamicDispatcher, Fetcher, Result};
use crate::{error::Error, hyperdrive::Hyperdrive};

Expand Down Expand Up @@ -89,6 +90,10 @@ impl Env {
pub fn hyperdrive(&self, binding: &str) -> Result<Hyperdrive> {
self.get_binding(binding)
}

pub fn vectorize(&self, binding: &str) -> Result<VectorizeIndex> {
self.get_binding(binding)
}
}

pub trait EnvBinding: Sized + JsCast {
Expand Down
2 changes: 2 additions & 0 deletions worker/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ pub use crate::router::{RouteContext, RouteParams, Router};
pub use crate::schedule::*;
pub use crate::socket::*;
pub use crate::streams::*;
pub use crate::vectorize::*;
pub use crate::version::*;
pub use crate::websocket::*;

Expand Down Expand Up @@ -226,6 +227,7 @@ mod schedule;
pub mod send;
mod socket;
mod streams;
mod vectorize;
mod version;
mod websocket;

Expand Down
Loading

0 comments on commit b598d71

Please sign in to comment.