Annotation Interface VectorSearch


Annotation to declare Vector Search queries directly on repository methods. Vector Search queries are used to search for similar documents based on vector embeddings typically returning SearchResults and limited by either a Score (within) or a Range of scores (between).

Vector search must define an index name using the indexName() attribute. The index must be created in the MongoDB Atlas cluster before executing the query. Any misspelling of the index name will result in returning no results.

When using pre-filters, you can either define filter() or use query derivation to define the pre-filter. Vector and distance parameters are considered once these are present. Vector search supports sorting and will consider Sort parameters.

Since:
5.0
Author:
Mark Paluch
See Also:
  • Element Details

    • searchType

      Configuration whether to use VectorSearchOperation.SearchType.ANN or VectorSearchOperation.SearchType.ENN for the search.
      Returns:
      the search type to use.
      Default:
      DEFAULT
    • indexName

      @AliasFor(annotation=Hint.class, value="indexName") String indexName
      Name of the Atlas Vector Search index to use. Atlas Vector Search doesn't return results if you misspell the index name or if the specified index doesn't already exist on the cluster.
      Returns:
      name of the Atlas Vector Search index to use.
    • path

      String path
      Indexed vector type field to search. This is defaulted from the domain model using the first Vector property found.
      Returns:
      an empty String by default.
      Default:
      ""
    • value

      Takes a MongoDB JSON (MQL) string defining the pre-filter against indexed fields. Supports Value Expressions. Alias for filter().
      Returns:
      an empty String by default.
      Default:
      ""
    • filter

      @AliasFor(annotation=Query.class, value="value") String filter
      Takes a MongoDB JSON (MQL) string defining the pre-filter against indexed fields. Supports Value Expressions. Alias for value().
      Returns:
      an empty String by default.
      Default:
      ""
    • limit

      String limit
      Number of documents to return in the results. This value can't exceed the value of numCandidates() if you specify numCandidates(). Limit accepts Value Expressions. A Vector Search method cannot define both, limit() and a Limit parameter. Supports Value Expressions.
      Returns:
      number of documents to return in the results.
      Default:
      ""
    • numCandidates

      String numCandidates
      Number of nearest neighbors to use during the search. Value must be less than or equal to (<=) 10000. You can't specify a number less than the number of documents to return. We recommend that you specify a number at least 20 times higher than the number of documents to return to increase accuracy.

      This over-request pattern is the recommended way to trade off latency and recall in your ANN searches, and we recommend tuning this parameter based on your specific dataset size and query requirements. Required if the query uses VectorSearchOperation.SearchType.ANN/VectorSearchOperation.SearchType.DEFAULT. Supports Value Expressions.

      Returns:
      number of nearest neighbors to use during the search.
      Default:
      ""