committed by
Mark Paluch
parent
eab7aae16c
commit
21568c84eb
@@ -25,7 +25,7 @@ Java::
|
||||
[source,java,indent=0,subs="verbatim,quotes",role="primary"]
|
||||
----
|
||||
VectorIndex index = new VectorIndex("vector_index")
|
||||
.addVector("plotEmbedding"), vector -> vector.dimensions(1536).similarity(COSINE)) <1>
|
||||
.addVector("plotEmbedding", vector -> vector.dimensions(1536).similarity(COSINE)) <1>
|
||||
.addFilter("year"); <2>
|
||||
|
||||
mongoTemplate.searchIndexOps(Movie.class) <3>
|
||||
|
||||
@@ -6,13 +6,13 @@ Annotated search methods use the `@VectorSearch` annotation to define parameters
|
||||
----
|
||||
interface CommentRepository extends Repository<Comment, String> {
|
||||
|
||||
@VectorSearch(indexName = "cos-index", filter = "{country: ?0}")
|
||||
SearchResults<WithVector> searchAnnotatedByCountryAndEmbeddingWithin(String country, Vector embedding,
|
||||
@VectorSearch(indexName = "cos-index", filter = "{country: ?0}", limit="100", numCandidates="2000")
|
||||
SearchResults<Comment> searchAnnotatedByCountryAndEmbeddingWithin(String country, Vector embedding,
|
||||
Score distance);
|
||||
|
||||
@VectorSearch(indexName = "my-index", filter = "{country: ?0}", numCandidates = "#{#limit * 20}",
|
||||
@VectorSearch(indexName = "my-index", filter = "{country: ?0}", limit="?3", numCandidates = "#{#limit * 20}",
|
||||
searchType = VectorSearchOperation.SearchType.ANN)
|
||||
List<WithVector> findAnnotatedByCountryAndEmbeddingWithin(String country, Vector embedding, Score distance, int limit);
|
||||
List<Comment> findAnnotatedByCountryAndEmbeddingWithin(String country, Vector embedding, Score distance, int limit);
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
@@ -6,14 +6,14 @@ MongoDB Search methods must use the `@VectorSearch` annotation to define the ind
|
||||
----
|
||||
interface CommentRepository extends Repository<Comment, String> {
|
||||
|
||||
@VectorSearch(indexName = "my-index")
|
||||
SearchResults<Comment> searchByEmbeddingNear(Vector vector, Score score);
|
||||
@VectorSearch(indexName = "my-index", numCandidates="200")
|
||||
SearchResults<Comment> searchTop10ByEmbeddingNear(Vector vector, Score score);
|
||||
|
||||
@VectorSearch(indexName = "my-index")
|
||||
SearchResults<Comment> searchByEmbeddingWithin(Vector vector, Range<Similarity> range);
|
||||
@VectorSearch(indexName = "my-index", numCandidates="200")
|
||||
SearchResults<Comment> searchTop10ByEmbeddingWithin(Vector vector, Range<Similarity> range);
|
||||
|
||||
@VectorSearch(indexName = "my-index")
|
||||
SearchResults<Comment> searchByCountryAndEmbeddingWithin(String country, Vector vector, Range<Similarity> range);
|
||||
@VectorSearch(indexName = "my-index", numCandidates="200")
|
||||
SearchResults<Comment> searchTop10ByCountryAndEmbeddingWithin(String country, Vector vector, Range<Similarity> range);
|
||||
}
|
||||
----
|
||||
====
|
||||
|
||||
@@ -4,12 +4,12 @@
|
||||
----
|
||||
interface CommentRepository extends Repository<Comment, String> {
|
||||
|
||||
@VectorSearch(indexName = "my-index")
|
||||
@VectorSearch(indexName = "my-index", numCandidates="#{#limit.max() * 20}")
|
||||
SearchResults<Comment> searchByCountryAndEmbeddingNear(String country, Vector vector, Score score,
|
||||
Limit limit);
|
||||
|
||||
@VectorSearch(indexName = "my-index")
|
||||
SearchResults<WithVector> searchAnnotatedByCountryAndEmbeddingWithin(String country, Vector embedding,
|
||||
@VectorSearch(indexName = "my-index", limit="10", numCandidates="200")
|
||||
SearchResults<Comment> searchByCountryAndEmbeddingWithin(String country, Vector embedding,
|
||||
Score score);
|
||||
|
||||
}
|
||||
@@ -17,3 +17,9 @@ interface CommentRepository extends Repository<Comment, String> {
|
||||
SearchResults<Comment> results = repository.searchByCountryAndEmbeddingNear("en", Vector.of(…), Score.of(0.9), Limit.of(10));
|
||||
----
|
||||
====
|
||||
|
||||
[TIP]
|
||||
====
|
||||
The MongoDB https://www.mongodb.com/docs/atlas/atlas-vector-search/vector-search-stage/[vector search aggregation] stage defines a set of required arguments and restrictions.
|
||||
Please make sure to follow the guidelines and make sure to provide required arguments like `limit`.
|
||||
====
|
||||
|
||||
@@ -9,13 +9,13 @@ The scoring function defaults to `ScoringFunction.unspecified()` as there is no
|
||||
interface CommentRepository extends Repository<Comment, String> {
|
||||
|
||||
@VectorSearch(…)
|
||||
SearchResults<Comment> searchByEmbeddingNear(Vector vector, Score similarity);
|
||||
SearchResults<Comment> searchTop10ByEmbeddingNear(Vector vector, Score similarity);
|
||||
|
||||
@VectorSearch(…)
|
||||
SearchResults<Comment> searchByEmbeddingNear(Vector vector, Similarity similarity);
|
||||
SearchResults<Comment> searchTop10ByEmbeddingNear(Vector vector, Similarity similarity);
|
||||
|
||||
@VectorSearch(…)
|
||||
SearchResults<Comment> searchByEmbeddingNear(Vector vector, Range<Similarity> range);
|
||||
SearchResults<Comment> searchTop10ByEmbeddingNear(Vector vector, Range<Similarity> range);
|
||||
}
|
||||
|
||||
repository.searchByEmbeddingNear(Vector.of(…), Score.of(0.9)); <1>
|
||||
|
||||
Reference in New Issue
Block a user