Does anyone know how I can use a MongoDB Atlas database as a vector store?
There is nothing in the documentation regarding the use of external databases.
Does anyone know how I can use a MongoDB Atlas database as a vector store?
There is nothing in the documentation regarding the use of external databases.
Example document schema:
json
Copy
{
"_id": <ObjectId>,
"content": "An interesting piece of text or metadata",
"vectorEmbedding": [0.123, 0.456, 0.789, ... ] // The embedding array
// any other fields you want...
}
Once the index is ready, you can run vector similarity queries via the $search
stage in an aggregation. You’ll want to use the $knnBeta
operator (or $vectorSearch
if available in your Atlas version).
For example, something like:
js
Copy
db.yourCollection.aggregate([
{
$search: {
index: "yourVectorIndexName",
knnBeta: {
vector: [0.111, 0.222, 0.333, ...], // query vector
path: "vectorEmbedding",
k: 5 // number of nearest neighbors
}
}
},
{
$project: {
content: 1,
score: { $meta: "searchScore" }
}
}
]);
k
determines how many similar documents are returned based on the distance metric (often cosine similarity).$meta: "searchScore"
can help you see the similarity ranking.you will have to do your own research on the best way to index but this is a good start.
good for you my good brother
I have api at good rate,my t-g:ynnmmoo
You might find this useful:
langchain_mongodb simplifies a lot
Yeah could go that route as well. There are lots of options depending on your abilities or if you want an easier drop in with out all the extra code. I like to do my own stuff when. I can
And that is good approach. It is always better to get the understanding of what is going on under the hood.