POST
/
v4
/
knowledge-bases
/
{knowledge_base_id}
/
query
JavaScript
import SGPClient from 'sgp';

const client = new SGPClient({
  apiKey: 'My API Key',
});

// Automatically fetches more pages as needed.
for await (const chunk of client.knowledgeBases.query('knowledge_base_id', { query: 'query', top_k: 1 })) {
  console.log(chunk.chunk_id);
}
{
  "chunks": [
    {
      "chunk_id": "<string>",
      "text": "<string>",
      "embedding": [
        123
      ],
      "metadata": {},
      "user_supplied_metadata": {},
      "attachment_url": "<string>",
      "title": "<string>",
      "score": 123
    }
  ],
  "started_at": "2023-11-07T05:31:56Z",
  "completed_at": "2023-11-07T05:31:56Z",
  "request_id": "<string>"
}

Authorizations

x-api-key
string
header
required

Path Parameters

knowledge_base_id
string
required

Body

application/json
query
string
required

The natural language query to be answered by referencing the data ingested into the knowledge base

top_k
integer
required

Number of chunks to return. Must be greater than 0 if specified. If not specified, all chunks will be returned.

Required range: 0 < x <= 10000
include_embeddings
boolean
default:true

Whether or not to include the embeddings for each chunk

metadata_filters
object

Optional filter by metadata fields, encoded as a JSON object

wildcard_filters
object

Optional wildcard filter for fields. Only fields that are part of the metadata will be accepted.

verbose
boolean
default:false

Enable or disable verbose logging

Response

Successful Response

chunks
ChunkV2 · object[]
required

An ordered list of the k most similar chunks and their similarity scores from most to least similar

started_at
string<date-time>

Timestamp at which the query was begun by the server.

completed_at
string<date-time>

Timestamp at which the query was completed by the server.

request_id
string

query request ID for verbose logging