encodeVector
Store a memory with an embedding you computed yourself, bypassing Brain's embedder.
encodeVector(input: EncodeVectorInput): Promise<EncodeResult>encodeVectorDirect(request: EncodeVectorDirectRequest): Promise<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.
modelFingerprintstring (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.
salienceHintfloatoptionalSeed 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
encodeVectorDirect 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.
import { newId, MemoryKindWire } from "@brain-db/sdk";
await client.encodeVectorDirect({
text: "Priya moved to Lisbon in March.",
vector: myEmbedding,
modelFingerprint: fp,
sessionId: 42n,
kind: MemoryKindWire.Episodic,
salienceHint: 0.6,
edges: [],
requestId: newId(),
txnId: null,
deduplicate: true,
});Was this page helpful?