encode_vector
Store a memory with an embedding you computed yourself, bypassing Brain's embedder.
async fn encode_vector(&self, input: &EncodeVectorInput) -> Result<EncodeResult, BrainHttpError>async fn encode_vector_direct(&self, request: &EncodeVectorDirectRequest) -> Result<EncodeResponse>Parameters
textstringrequiredThe memory text. Still required — it is what recall returns and what the lexical retriever indexes.
vectorfloat[]requiredThe embedding. Its length must equal the shard's vectorDim — read it from capabilities. Any other length is rejected.
model_fingerprintstring (wire: bytes)requiredWhich model produced the vector. Brain refuses to mix fingerprints inside one space, because cosine distance between two models' vectors is meaningless. A mismatch is BadModelFingerprint, not a silent bad result.
session64-bit integeroptionalThe session to attribute it to.
kindintegeroptionalForce the memory kind instead of letting Brain classify it.
salience_hintfloatoptionalSeed salience in [0, 1] instead of letting the pipeline score it.
deduplicatebooleanoptionalWhether to run the dedup check. Defaults to on.
Returns
—EncodeResultalwaysThe same shape encode returns: memoryId, wasDeduplicated, salience, kind, createdAtUnixNanos, autoEdgesAdded.
The wire form
encode_vector_direct takes no builder, and every field is explicit: text,
vector, modelFingerprint (bytes here, not a string), sessionId,
kind, salienceHint, edges (memory edges to attach at write time),
requestId, txnId, deduplicate, and an optional actAs. It is the only
write verb that can attach edges in the same call.
A space's vectors must all come from the same model. There is no migration verb: changing embedding model means re-encoding the space. Decide the model before you load data, not after.
use brain_db_sdk::{new_id, wire::types::{EncodeVectorDirectRequest, MemoryKindWire}};
client
.encode_vector_direct(&EncodeVectorDirectRequest {
text: "Priya moved to Lisbon in March.".into(),
vector: my_embedding,
model_fingerprint: fp,
session_id: 42,
kind: MemoryKindWire::Episodic,
salience_hint: 0.6,
edges: vec![],
request_id: new_id(),
txn_id: None,
deduplicate: true,
act_as: None,
})
.await?;Was this page helpful?