40 Add or Store Embeddings
This section describes how to store embeddings in vector columns using either client-provided vectors (BYOV) or service-generated embeddings (Auto Trigger / Auto Scheduler).
Parent topic: Vectors
40.1 Storing Embeddings Using BYOV
In BYOV mode, the client generates embeddings and passes the embedding data to SDK APIs.
import { doc, setDoc, denseVector, sparseVector, deleteVector } from "fusabase/oracledb";
// Base reference
const reviewsRef = doc(db, "users", "Scott", "reviews", "cookies-id-1");
// Add a review for the recipe Cookies.
await setDoc(reviewsRef, {
recipe_id: "Cookies",
comment: "The Cookies recipe was easy to follow, and was super delicious. Easy to bake and produces a great munching sound.",
review_emb: denseVector([0.12, -0.91, 0.44]),
recipe_emb: sparseVector(1000, [3, 40, 777], [0.5, 0.8, 0.33]),
});import oracledb from "fusabase-ns/oracledb";
db.collection("users").doc("Scott")
.collection("reviews").doc("cookies-id-1")
.set({
"recipe_id": "Cookies",
"comment": "The Cookies recipe was easy to follow, and was super delicious. Easy to bake and produces a great munching sound.",
"review_emb": oracledb.FieldValue.denseVector([0.12, -0.91, 0.44]),
"recipe_emb": oracledb.FieldValue.sparseVector(1000, [3, 40, 777], [0.5, 0.8, 0.33]),
});import com.oracle.mobile.fusabase.oracledb.FieldValue;
import com.oracle.mobile.fusabase.oracledb.FusabaseOracledb;
import com.oracle.mobile.fusabase.oracledb.SetOptions;
import com.oracle.mobile.fusabase.oracledb.VectorValue;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
FusabaseOracledb db = FusabaseOracledb.getInstance();
// Add a review for the recipe Cookies.
Map<String, Object> review = new HashMap<>();
review.put("recipe_id", "Cookies");
review.put("comment", "The Cookies recipe was easy to follow, and was super delicious. Easy to bake and produces a great munching sound.");
review.put("review_emb", VectorValue.denseEmbedding(
Arrays.asList(0.12, -0.44, 0.91)
));
review.put("recipe_emb", VectorValue.sparseEmbedding(
1024,
Arrays.asList(12, 57, 301),
Arrays.asList(0.8, 0.24, 0.93)
));
db.collection("users")
.document("Scott")
.collection("reviews")
.document("cookies-id-1")
.set(review, SetOptions.merge()); // Base reference
final DocumentReference reviewRef = db
.collection('users')
.doc('Scott')
.collection('reviews')
.doc('cookies-id-1');
// Add a review for the recipe Cookies.
await reviewRef.set({
'recipe_id': 'Cookies',
'comment': 'The Cookies recipe was easy to follow, and was super delicious. Easy to bake and produces a great munching sound.',
'review_emb': FieldValue.denseVector([0.12, -0.44, 0.91]),
'recipe_emb': FieldValue.sparseVector(1000, [3, 40, 777], [0.5, 0.8, 0.33]),
});import FusabaseOracledb
let db = FusabaseOracledb.oracledb()
let reviewRef = db
.collection("users")
.document("Scott")
.collection("reviews")
.document("cookies-id-1")
// Add a review for the recipe Cookies.
reviewRef.setData([
"recipe_id": "Cookies",
"comment": "The Cookies recipe was easy to follow, and was super delicious. Easy to bake and produces a great munching sound.",
"review_emb": try denseVector([0.12, -0.91, 0.44]),
"recipe_emb": try sparseVector(
dimension: 1000,
indices: [2, 7, 900],
values: [0.9, 0.3, 0.5]
),
])Parent topic: Add or Store Embeddings
40.2 Storing Embeddings Using Auto Trigger / Auto Scheduler
When the collection is set up with AUTO_TRIGGER or
AUTO_SCHEDULER, you don't pass the embedding at all. Just insert
your document like normal. The database fills in the vector column itself, using
whichever source you configured.
This means your application code doesn't change between BYOV and auto-generation
collections, except for the absence of the vector field. Same addDoc
and setDoc calls.
See Also:
Console Steps: Creating Collections with Vectors for detailed steps on how to set up AUTO_TRIGGER or
AUTO_SCHEDULER
Parent topic: Add or Store Embeddings