Docs · API reference
MongoDB API reference.
FermionDB speaks the MongoDB wire protocol, so you use the MongoDB drivers and query language you already know. This page covers connecting, indexing and vector search, and lists what FermionDB supports.
Connect
Point any MongoDB driver at your FermionDB address. Nothing else changes.
from pymongo import MongoClient
client = MongoClient("mongodb://HOST:PORT")
products = client.shop.productsCreate the indexes
One vector index per collection, plus a regular index on each field you filter by. Create them before you load documents.
# Regular indexes on the fields you filter by
products.create_index([("in_stock", 1)])
products.create_index([("category", 1)])
# The vector index
client.shop.command({
"createSearchIndex": "products",
"name": "products_vec",
"type": "vectorSearch",
"definition": {"fields": [{
"type": "vector", "path": "embedding",
"numDimensions": 1536, "similarity": "cosine",
}]},
})$vectorSearch
The first stage of an aggregation pipeline. Later stages work on its results as usual.
results = products.aggregate([
{"$vectorSearch": {
"index": "products_vec",
"path": "embedding",
"queryVector": embedding, # 1,536 numbers, same as the index
"numCandidates": 200,
"limit": 10,
"filter": {"in_stock": True, "category": {"$in": ["shoes", "bags"]}},
}},
{"$project": {"name": 1, "price": 1, "score": {"$meta": "vectorSearchScore"}}},
])| Parameter | Type | Meaning |
|---|---|---|
| index | string | Name of the collection's vector index. |
| path | string | Field that holds the vector. |
| queryVector | number[] | The query embedding. Same length as the index's numDimensions. |
| numCandidates | integer | How many candidates the search considers before returning the best. Higher is more thorough. |
| limit | integer | How many documents to return. |
| filter | document | Optional. Conditions on indexed fields, checked during the search. |
Each result's similarity score is available as { $meta: "vectorSearchScore" } in a $project stage.
Supported MongoDB API
What FermionDB supports today. Need something that isn't listed? Tell us when you request early access.
- Drivers
Any MongoDB driverPyMongoNode.jsGoJavamongosh- Pipeline stages
$vectorSearch$match$project$group$sort$limit- $vectorSearch filter
Equality$in$nin$ne- $match operators
Equality$in$gte$regex- Expressions
$sum$meta: "vectorSearchScore"- Commands
insertManyaggregatecreateIndexcreateSearchIndexlistSearchIndexes- Indexes
Vector (cosine)Single-field