Skip to main content
POST
/
v4
/
chunks
/
rank
JavaScript
import SGPClient from 'sgp';

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

const rankedChunksResponse = await client.chunks.rank({
  query: 'query',
  rank_strategy: { method: 'cross_encoder' },
  relevant_chunks: [{ chunk_id: 'chunk_id', score: 0, text: 'text' }],
});

console.log(rankedChunksResponse.relevant_chunks);
{
  "relevant_chunks": [
    {
      "chunk_id": "<string>",
      "text": "<string>",
      "embedding": [
        123
      ],
      "metadata": {},
      "user_supplied_metadata": {},
      "attachment_url": "<string>",
      "title": "<string>",
      "score": 123
    }
  ]
}

Authorizations

x-api-key
string
header
required

Body

application/json
query
string
required

Natural language query to re-rank chunks against. If a vector store query was originally used to retrieve these chunks, please use the same query for this ranking

relevant_chunks
ChunkV2 · object[]
required

List of chunks to rank

rank_strategy
object
required

The ranking strategy to use.

Rank strategies determine how the ranking is done, They consist of the ranking method name and additional params needed to compute the ranking.

Use the built-in cross_encoder or rouge strategies or create a custom one with the Models API.

  • CrossEncoderRankStrategy
  • RougeRankStrategy
  • ModelRankStrategy
  • AzureAIFoundryRankStrategy
top_k
integer

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

Required range: x > 0
account_id
string

Account to rank chunks with. If you have access to more than one account, you must specify an account_id

Response

Successful Response

relevant_chunks
ChunkV2 · object[]
required

List of chunks ranked by the requested rank strategy

I