use sim_kernel::Expr;
pub const GATEWAY_VECTOR_STORE_KIND: &str = "openai-gateway/vector-store";
pub const GATEWAY_VECTOR_STORE_ITEM_KIND: &str = "openai-gateway/vector-store-item";
#[derive(Clone, Debug, PartialEq)]
pub struct GatewayVectorStore {
id: String,
name: String,
created_at_ms: u64,
items: Vec<GatewayVectorStoreItem>,
}
impl GatewayVectorStore {
pub fn new(
id: impl Into<String>,
name: impl Into<String>,
created_at_ms: u64,
items: Vec<GatewayVectorStoreItem>,
) -> Self {
Self {
id: id.into(),
name: name.into(),
created_at_ms,
items,
}
}
pub fn id(&self) -> &str {
&self.id
}
pub fn name(&self) -> &str {
&self.name
}
pub fn created_at_ms(&self) -> u64 {
self.created_at_ms
}
pub fn items(&self) -> &[GatewayVectorStoreItem] {
&self.items
}
pub fn to_expr(&self) -> Expr {
Expr::Map(vec![
field("kind", Expr::String(GATEWAY_VECTOR_STORE_KIND.to_owned())),
field("id", Expr::String(self.id.clone())),
field("name", Expr::String(self.name.clone())),
field(
"created-at-ms",
Expr::String(self.created_at_ms.to_string()),
),
field(
"items",
Expr::Vector(
self.items
.iter()
.map(GatewayVectorStoreItem::to_expr)
.collect(),
),
),
])
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct GatewayVectorStoreItem {
id: String,
text: String,
embedding: Vec<f64>,
}
impl GatewayVectorStoreItem {
pub fn new(id: impl Into<String>, text: impl Into<String>, embedding: Vec<f64>) -> Self {
Self {
id: id.into(),
text: text.into(),
embedding,
}
}
pub fn id(&self) -> &str {
&self.id
}
pub fn text(&self) -> &str {
&self.text
}
pub fn embedding(&self) -> &[f64] {
&self.embedding
}
pub fn to_expr(&self) -> Expr {
Expr::Map(vec![
field(
"kind",
Expr::String(GATEWAY_VECTOR_STORE_ITEM_KIND.to_owned()),
),
field("id", Expr::String(self.id.clone())),
field("text", Expr::String(self.text.clone())),
field(
"embedding",
Expr::Vector(
self.embedding
.iter()
.map(|value| Expr::String(format!("{value:.6}")))
.collect(),
),
),
])
}
}
use sim_value::build::entry as field;