TechnologySeptember 6, 2023

Build a Text and Image Search App with Astra DB Vector Search, NodeJS, Stargate’s New JSON API, and Stargate-Mongoose

Yuqi Du
Yuqi DuEngineering
Build a Text and Image Search App with Astra DB Vector Search, NodeJS, Stargate’s New JSON API, and Stargate-Mongoose
const photoSchema = new mongoose.Schema({
  //schema fields
});
cons Photo = mongoose.model('photo', photoSchema);
const photosOfCategory = await Photo.find({ 'category': categoryName }).limit(limitNumber);
const photo = await Photo.findById(photoId);
const newPhoto = new Photo({
      name: req.body.name,
      description: req.body.description,
      category: req.body.category,
      image: newImageName,
      "$vector": description_embedding,  
    });
await newPhoto.save();
const description_embedding = await getTextEmbedding(searchTerm);
cosnt photos = await Photo.find({}).sort({ $vector: { $meta:
description_embedding } }).limit(3);
const photo_embedding = await getPhotoEmbedding(image); 
const photos = await PhotoEmbedding.find({}).sort({ $vector: { $meta:
photo_embedding } }).limit(3);
Discover more
Vector SearchStargateNode.js
Share

One-stop Data API for Production GenAI

Astra DB gives JavaScript developers a complete data API and out-of-the-box integrations that make it easier to build production RAG apps with high relevancy and low latency.