v1

latestOpenAPI 3.0.3Apache 2.02026-07-2685172326.0 KB
Vector Operations

Search with a vector

Search a namespace using a query vector. It retrieves the ids of the most similar items in a namespace, along with their similarity scores.

For guidance, examples, and limits, see Search.

post/query

Headers

X-Pinecone-Api-Versionstring required

Required date-based version header

Request body

namespacestring

The namespace to query.

topKinteger required

The number of results to return for each query.

filterobject

The filter to apply. You can use vector metadata to limit your search. See Understanding metadata.

includeValuesboolean

Indicates whether vector values are included in the response. For on-demand indexes, setting this to true may increase latency, especially with higher topK values, because vector values are retrieved from object storage. Unless you need vector values, set this to false for better performance.

includeMetadataboolean

Indicates whether metadata is included in the response as well as the ids.

vectornumber[]

The query vector. This should be the same length as the dimension of the index being queried. Each query request can contain only one of the parameters id or vector.

idstring

The unique ID of the vector to be used as a query vector. Each request can contain either the vector or id parameter.

scanFactornumber float

An optimization parameter for IVF dense indexes in dedicated read node indexes. It adjusts how much of the index is scanned to find vector candidates. Range: 0.5 – 4 (default). Keep the default (4.0) for the best search results. If query latency is too high, try lowering this value incrementally (minimum 0.5) to speed up the search at the cost of slightly lower accuracy. This parameter is only supported for dedicated (DRN) dense indexes.

maxCandidatesinteger

An optimization parameter that controls the maximum number of candidate dense vectors to rerank. Reranking computes exact distances to improve recall but increases query latency. Range: top_k – 100000. Keep the default for a balance of recall and latency. Increase this value if recall is too low, or decrease it to reduce latency at the cost of accuracy. This parameter is only supported for dedicated (DRN) dense indexes.

Example request

{
  "namespace": "example-namespace",
  "topK": 10,
  "filter": {
    "genre": {
      "$in": [
        "comedy",
        "documentary",
        "drama"
      ]
    },
    "year": {
      "$eq": 2019
    }
  },
  "includeValues": true,
  "includeMetadata": true,
  "queries": [
    {
      "values": [
        0.1,
        0.2,
        0.3,
        0.4,
        0.5,
        0.6,
        0.7,
        0.8
      ],
      "sparseValues": {
        "indices": [
          1,
          312,
          822,
          14,
          980
        ],
        "values": [
          0.1,
          0.2,
          0.3,
          0.4,
          0.5
        ]
      },
      "topK": 10,
      "namespace": "example-namespace",
      "filter": {
        "genre": {
          "$in": [
            "comedy",
            "documentary",
            "drama"
          ]
        },
        "year": {
          "$eq": 2019
        }
      }
    }
  ],
  "vector": [
    0.1,
    0.2,
    0.3,
    0.4,
    0.5,
    0.6,
    0.7,
    0.8
  ],
  "sparseVector": {
    "indices": [
      1,
      312,
      822,
      14,
      980
    ],
    "values": [
      0.1,
      0.2,
      0.3,
      0.4,
      0.5
    ]
  },
  "id": "example-vector-1",
  "scanFactor": 2,
  "maxCandidates": 1000
}

Response

A successful response.

namespacestring

The namespace for the vectors.

Example response

{
  "results": [
    {
      "matches": [
        {
          "id": "example-vector-1",
          "score": 0.08,
          "values": [
            0.1,
            0.2,
            0.3,
            0.4,
            0.5,
            0.6,
            0.7,
            0.8
          ],
          "sparseValues": {
            "indices": [
              1,
              312,
              822,
              14,
              980
            ],
            "values": [
              0.1,
              0.2,
              0.3,
              0.4,
              0.5
            ]
          },
          "metadata": {
            "genre": "documentary",
            "year": 2019
          }
        }
      ],
      "namespace": "example-namespace"
    }
  ],
  "matches": [
    {
      "id": "example-vector-1",
      "score": 0.08,
      "values": [
        0.1,
        0.2,
        0.3,
        0.4,
        0.5,
        0.6,
        0.7,
        0.8
      ],
      "sparseValues": {
        "indices": [
          1,
          312,
          822,
          14,
          980
        ],
        "values": [
          0.1,
          0.2,
          0.3,
          0.4,
          0.5
        ]
      },
      "metadata": {
        "genre": "documentary",
        "year": 2019
      }
    }
  ],
  "usage": {
    "readUnits": 5
  }
}