Vector Search
#13994
Replies: 2 comments 6 replies
-
Vector search in MongoDB is just an aggregation stage, so you can use it with Mongoose's |
Beta Was this translation helpful? Give feedback.
1 reply
-
Here is a script for Vector Search Implementation const mongoose = require('mongoose');
const vectorSchema = new mongoose.Schema({
plot: String,
genres: [String],
year: Number,
myVector: [Number]
});
const Embedded = mongoose.model('vectortest', vectorSchema, 'vectortest');
async function run() {
await mongoose.connect('');
// await mongoose.connection.dropDatabase();
await Embedded.create({
plot: 'Test plot A',
genres: ['Action', 'Adventure', 'Family'],
year: 1993,
myVector: [0.75, 0.1]
});
const agg = [
{
'$vectorSearch': {
'index': 'vector_index',
'path': 'myVector',
'queryVector': [0.75, 0.1], // Adjust the query vector as needed
'numCandidates': 6,
'limit': 1
}
},
{
'$project': {
'_id': 0,
'plot': 1,
'genres': 1,
'year': 1,
'score': {
'$meta': 'vectorSearchScore'
}
}
}
];
const res = await Embedded.aggregate(agg);
console.log('Search result:', res);
console.log('Done');
}
run(); |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
When will we get Vector Search implementation?
Beta Was this translation helpful? Give feedback.
All reactions