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
- application/json
Body
required
- MOD1
- MOD2
Array [
]
Array [
- SearchSelection
- SemanticSearchSelection
- MOD1
- MOD2
Array [
]
]
Possible values: >= 1
query
object
required
oneOf
string
number
Possible values: [search_document
, search_query
, null
]
Default value: search_query
selection
object
Possible values: [composition
]
Default value: true
Possible values: [ANY
, ALL
]
cherries
object
Default value: true
Possible values: [cherrypick
]
Possible values: >= 2
, <= 2
Default value: ``
Possible values: >= 2
, <= 2
Default value: ``
filters
object[]
oneOf
Default value: true
Possible values: [search
]
Default value: true
Default value: true
Possible values: [semanticSearch
]
Possible values: [dot
, l2
]
Default value: dot
embedding
object
required
oneOf
number
string
Possible values: >= 2
, <= 2
Possible values: [search_document
, search_query
]
Responses
- 200
- 400
- 401
Successful response
- application/json
- Schema
- Example (from schema)
Schema
Array [
]
data
object[]
required
{
"data": [
{
"id": "string"
}
]
}
Bad request
Unauthorized