Skip to main content

k-NN Search

POST 

/v1/query/topk

Get sorted results of the top k most semantically similar data points to your query.

The below example demonstrates how to make a POST request to the Top K query endpoint using Python's requests library. It includes setting up the payload with a filter for "New York" in the text field and a k-NN Query for "financial news".

The results will be 50 data points that contain the text "New York" and are most semantically related to "financial news".

See the capabilities section for a more detailed walkthrough.

import requests
import json

# Top K endpoint
url = "https://api-atlas.nomic.ai/v1/query/topk"

# Request payload
payload = {
"projection_id": "d50b79ea-910d-4975-9930-b5ce0736fbd0",
"k": 50,
"query": "financial news",
"selection": {
"polarity": True,
"method": "composition",
"conjunctor": "ALL",
"filters": [
{
"method": "search",
"query": "New York",
"field": "text",
}
]
}
}

# Set the headers
headers = {
"Content-Type": "application/json",
"Authorization": "Bearer <Your API Key>"
}

# Send the POST request
response = requests.post(url, data=json.dumps(payload), headers=headers)

Request

Body

required

    k integerrequired

    Possible values: >= 1

    query

    object

    required

    oneOf

    string

    task_type string

    Possible values: [search_document, search_query, null]

    Default value: search_query

    projection_id uuidrequired

    selection

    object

    method stringrequired

    Possible values: [composition]

    polarity boolean

    Default value: true

    conjunctor stringrequired

    Possible values: [ANY, ALL]

    cherries

    object

    polarity boolean

    Default value: true

    method stringrequired

    Possible values: [cherrypick]

    added array[]

    Possible values: >= 2, <= 2

    Default value: ``

    removed array[]

    Possible values: >= 2, <= 2

    Default value: ``

    field stringnullable

    filters

    object[]

  • Array [

  • oneOf

    polarity boolean

    Default value: true

    method stringrequired

    Possible values: [search]

    query stringrequired
    field stringrequired
    ignoreCase boolean

    Default value: true

    regex boolean
    wordBoundary boolean
  • ]

Responses

Successful response

Schema

    data

    object[]

    required

  • Array [

  • id stringrequired
  • ]

Loading...