Class MongoDbEmbeddingStore
java.lang.Object
dev.langchain4j.store.embedding.mongodb.MongoDbEmbeddingStore
- All Implemented Interfaces:
EmbeddingStore<TextSegment>
Represents a MongoDB indexed collection as an embedding store.
More info on using MongoDb vector search.
tutorial how to use vector search with MongoDB Atlas (great starting point).
To deploy a local instance of Atlas, see this guide.
If you are using a free tier, #createIndex = true might not be supported,
so you will need to create an index manually.
In your Atlas web console go to: DEPLOYMENT -> Database -> {your cluster} -> Atlas Search tab
-> Create Index Search -> "JSON Editor" under "Atlas Vector Search" (not "Atlas Search") -> Next
-> Select your database in the left pane -> Insert the following JSON into the right pane
(set "numDimensions" and additional metadata fields to desired values)
{
"fields" : [ {
"type" : "vector",
"path" : "embedding",
"numDimensions" : 384,
"similarity" : "cosine"
}, {
"type" : "filter",
"path" : "metadata.test-key"
} ]
}
-> Next -> Create Search Index-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionMongoDbEmbeddingStore(com.mongodb.client.MongoClient mongoClient, String databaseName, String collectionName, String indexName, Long maxResultRatio, com.mongodb.client.model.CreateCollectionOptions createCollectionOptions, org.bson.conversions.Bson filter, IndexMapping indexMapping, Boolean createIndex) -
Method Summary
Modifier and TypeMethodDescriptionadd(Embedding embedding, TextSegment textSegment) voidvoidbuilder()voidvoidvoidremoveAll(Collection<String> ids) search(EmbeddingSearchRequest request) Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface EmbeddingStore
addAll, generateIds, remove
-
Constructor Details
-
MongoDbEmbeddingStore
public MongoDbEmbeddingStore(com.mongodb.client.MongoClient mongoClient, String databaseName, String collectionName, String indexName, Long maxResultRatio, com.mongodb.client.model.CreateCollectionOptions createCollectionOptions, org.bson.conversions.Bson filter, IndexMapping indexMapping, Boolean createIndex)
-
-
Method Details
-
builder
-
add
- Specified by:
addin interfaceEmbeddingStore<TextSegment>
-
add
- Specified by:
addin interfaceEmbeddingStore<TextSegment>
-
add
- Specified by:
addin interfaceEmbeddingStore<TextSegment>
-
addAll
- Specified by:
addAllin interfaceEmbeddingStore<TextSegment>
-
removeAll
public void removeAll()- Specified by:
removeAllin interfaceEmbeddingStore<TextSegment>
-
removeAll
- Specified by:
removeAllin interfaceEmbeddingStore<TextSegment>
-
removeAll
- Specified by:
removeAllin interfaceEmbeddingStore<TextSegment>
-
search
- Specified by:
searchin interfaceEmbeddingStore<TextSegment>
-
addAll
- Specified by:
addAllin interfaceEmbeddingStore<TextSegment>
-