Search with Advanced Options

Optionally use the advanced_options parameter of the query operation to further customize semantic searches.

For details about implementing the query operation using Python, Curl, and PL/SQL, see Semantic Search.

The advanced_options (advancedOptions when using a Curl request) parameter can be used to provide search tuning parameters. The following are supported:

  • distance_metric: Optionally used to override the default metric with a metric of your choice. The supported metrics are as follows:

    • COSINE (default)
    • MANHATTAN
    • HAMMING
    • JACCARD
    • DOT
    • EUCLIDEAN
    • L2_SQUARED
    • EUCLIDEAN_SQUARED

    For more information about the available distance metrics, see Vector Distance Metrics in Oracle AI Database AI Vector Search User's Guide.

  • accuracy: Trade-off between speed and accuracy, provided as a number from 0 to 100.

    More information about target accuracy can be found at Understand Approximate Similarity Search Using Vector Indexes in Oracle AI Database AI Vector Search User's Guide.

  • idx_parameters: Index-specific parameters. For example, the following values can be specified:

    "idx_parameters" : {
      "efsearch" : <number>,
      "neighbor partition probes" : <number>
    }

    The efsearch parameter is used to impose a certain maximum number of candidates to be considered while probing a vector index.

    The neighbor partition probes parameter is used to impose a certain maximum number of partitions to be probed by the search.

See the following for a Python example of a semantic search using query with advanced_options to specify a distance metric and target accuracy:

from oracle_vecdb import OracleVecDB, Configuration

client = OracleVecDB(Configuration(
    rest_url="https://<host>/ords/<schema>/_/db-api/stable/vecdb/",
    access_token="<bearer-token>", # or username="<user>", password="<pass>"
))

#search using a specified distance metric
distance_metric_results = client.query(
    table_name='products',
    query_by={'text': 'laptop'},
    top_k=10,
    advanced_options={
        'distance_metric': 'EUCLIDEAN',
        'accuracy': 95,
        'idx_parameters': {
            'efsearch': 128,
            'neighbor partition probes': 4
        }
    },
    include_vectors=True
)

print(distance_metric_results)

Example response:

{
    "items": [
        {
            "id": "prod_001",
            "metadata": {
                "name": "Aurora Trail Boots",
                "category": "footwear",
                "price": 129.99,
                "color": "midnight blue"
            },
            "vector": null,
            "distance": 0.0
        },
        {
            "id": "prod_008",
            "metadata": {
                "name": "Glacier Insulated Bottle",
                "category": "accessories",
                "price": 34.0,
                "color": "arctic white"
            },
            "vector": null,
            "distance": 0.00393
        }
    ]
}