RerankResponse

Contains reranked document scores.

For the list of response object types, see Response Objects.

Use RerankResponse to inspect reranked items and to access scores through list-style indexing.

Attributes

Attribute Type Description
items list of RerankResultItem Reranked result items.

RerankResultItem

Represents one reranked result returned in the items list of a RerankResponse.

Attributes

Attribute Type Description
index int Zero-based index of the document in the input list.
score int or float Relevance score assigned by the reranking model.

Iterate Items

Iterate over response.items to inspect each reranked result.

response = client.rerank(
    model_name="reranker_model",
    query="best trail shoes",
    documents=["Trail running shoes with durable grip.", "Formal leather shoes."],
)

for item in response.items:
    print(item.index, item.score)

Methods

Method Return Type Description
len(response) int Returns the number of reranked result items.
response[index] RerankResultItem Returns the reranked result item at the specified zero-based index.
model_dump() dict[str, Any] Returns a Pydantic dictionary representation of the object.
model_dump_json() str Returns a Pydantic JSON string representation of the object.
to_dict() dict[str, Any] Returns a dictionary representation compatible with earlier SDK response handling.
to_json() str Returns a JSON string representation compatible with earlier SDK response handling.
to_str() str Returns a readable string representation compatible with earlier SDK response handling.

Iterate Attributes

Use serialization helpers to iterate response attributes and item attributes.

response = client.rerank(
    model_name="reranker_model",
    query="best trail shoes",
    documents=[
        "Trail running shoes with durable grip.",
        "Formal leather shoes.",
        "Waterproof hiking shoes.",
    ],
)

payload = response.to_dict()

for attribute, value in payload.items():
    print(attribute, value)

for item in response.items:
    item_payload = item.to_dict()
    for attribute, value in item_payload.items():
        print(attribute, value)

Sample Response

{
  "items": [
    {
      "index": 0,
      "score": 0.9821
    },
    {
      "index": 2,
      "score": 0.8114
    }
  ]
}

Returned By

Returned by: rerank().