MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / vector_insert_field_impl

Method vector_insert_field_impl

nodedb-client/src/remote/client/vector.rs:65–96  ·  view source on GitHub ↗
(
        &self,
        collection: &str,
        field_name: &str,
        id: &str,
        embedding: &[f32],
        metadata: Option<Document>,
    )

Source from the content-addressed store, hash-verified

63 }
64
65 pub(super) async fn vector_insert_field_impl(
66 &self,
67 collection: &str,
68 field_name: &str,
69 id: &str,
70 embedding: &[f32],
71 metadata: Option<Document>,
72 ) -> NodeDbResult<()> {
73 // Field-aware path: emit `INSERT INTO <coll> (id, <field>[,
74 // metadata]) VALUES ($1, ARRAY[...]<, $2>)` so the vector lands
75 // on the column named by the trait — not on whichever vector
76 // column the planner picks when the column name is omitted.
77 let coll = quote_identifier(collection);
78 let field = quote_identifier(field_name);
79 let vec_lit = format_vector_array(embedding);
80
81 let sql = match metadata {
82 Some(_) => {
83 format!("INSERT INTO {coll} (id, {field}, metadata) VALUES ($1, {vec_lit}, $2)")
84 }
85 None => format!("INSERT INTO {coll} (id, {field}) VALUES ($1, {vec_lit})"),
86 };
87
88 if let Some(d) = metadata {
89 let meta_json = sonic_rs::to_string(&d)
90 .map_err(|e| NodeDbError::storage(format!("metadata serialization: {e}")))?;
91 self.execute_raw(&sql, &[&id, &meta_json]).await?;
92 } else {
93 self.execute_raw(&sql, &[&id]).await?;
94 }
95 Ok(())
96 }
97
98 pub(super) async fn vector_search_field_impl(
99 &self,

Callers 1

vector_insert_fieldMethod · 0.80

Calls 3

quote_identifierFunction · 0.85
format_vector_arrayFunction · 0.85
execute_rawMethod · 0.80

Tested by

no test coverage detected