All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.cohere.api.requests.RerankRequest Maven / Gradle / Ivy

There is a newer version: 1.6.0
Show newest version
/**
 * This file was auto-generated by Fern from our API Definition.
 */
package com.cohere.api.requests;

import com.cohere.api.core.ObjectMappers;
import com.cohere.api.types.RerankRequestDocumentsItem;
import com.fasterxml.jackson.annotation.JsonAnyGetter;
import com.fasterxml.jackson.annotation.JsonAnySetter;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.annotation.Nulls;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

@JsonInclude(JsonInclude.Include.NON_EMPTY)
@JsonDeserialize(builder = RerankRequest.Builder.class)
public final class RerankRequest {
    private final Optional model;

    private final String query;

    private final List documents;

    private final Optional topN;

    private final Optional> rankFields;

    private final Optional returnDocuments;

    private final Optional maxChunksPerDoc;

    private final Map additionalProperties;

    private RerankRequest(
            Optional model,
            String query,
            List documents,
            Optional topN,
            Optional> rankFields,
            Optional returnDocuments,
            Optional maxChunksPerDoc,
            Map additionalProperties) {
        this.model = model;
        this.query = query;
        this.documents = documents;
        this.topN = topN;
        this.rankFields = rankFields;
        this.returnDocuments = returnDocuments;
        this.maxChunksPerDoc = maxChunksPerDoc;
        this.additionalProperties = additionalProperties;
    }

    /**
     * @return The identifier of the model to use, one of : rerank-english-v3.0, rerank-multilingual-v3.0, rerank-english-v2.0, rerank-multilingual-v2.0
     */
    @JsonProperty("model")
    public Optional getModel() {
        return model;
    }

    /**
     * @return The search query
     */
    @JsonProperty("query")
    public String getQuery() {
        return query;
    }

    /**
     * @return A list of document objects or strings to rerank.
     * If a document is provided the text fields is required and all other fields will be preserved in the response.
     * 

The total max chunks (length of documents * max_chunks_per_doc) must be less than 10000.

*

We recommend a maximum of 1,000 documents for optimal endpoint performance.

*/ @JsonProperty("documents") public List getDocuments() { return documents; } /** * @return The number of most relevant documents or indices to return, defaults to the length of the documents */ @JsonProperty("top_n") public Optional getTopN() { return topN; } /** * @return If a JSON object is provided, you can specify which keys you would like to have considered for reranking. The model will rerank based on order of the fields passed in (i.e. rank_fields=['title','author','text'] will rerank using the values in title, author, text sequentially. If the length of title, author, and text exceeds the context length of the model, the chunking will not re-consider earlier fields). If not provided, the model will use the default text field for ranking. */ @JsonProperty("rank_fields") public Optional> getRankFields() { return rankFields; } /** * @return
    *
  • If false, returns results without the doc text - the api will return a list of {index, relevance score} where index is inferred from the list passed into the request.
  • *
  • If true, returns results with the doc text passed in - the api will return an ordered list of {index, text, relevance score} where index + text refers to the list passed into the request.
  • *
*/ @JsonProperty("return_documents") public Optional getReturnDocuments() { return returnDocuments; } /** * @return The maximum number of chunks to produce internally from a document */ @JsonProperty("max_chunks_per_doc") public Optional getMaxChunksPerDoc() { return maxChunksPerDoc; } @java.lang.Override public boolean equals(Object other) { if (this == other) return true; return other instanceof RerankRequest && equalTo((RerankRequest) other); } @JsonAnyGetter public Map getAdditionalProperties() { return this.additionalProperties; } private boolean equalTo(RerankRequest other) { return model.equals(other.model) && query.equals(other.query) && documents.equals(other.documents) && topN.equals(other.topN) && rankFields.equals(other.rankFields) && returnDocuments.equals(other.returnDocuments) && maxChunksPerDoc.equals(other.maxChunksPerDoc); } @java.lang.Override public int hashCode() { return Objects.hash( this.model, this.query, this.documents, this.topN, this.rankFields, this.returnDocuments, this.maxChunksPerDoc); } @java.lang.Override public String toString() { return ObjectMappers.stringify(this); } public static QueryStage builder() { return new Builder(); } public interface QueryStage { _FinalStage query(String query); Builder from(RerankRequest other); } public interface _FinalStage { RerankRequest build(); _FinalStage model(Optional model); _FinalStage model(String model); _FinalStage documents(List documents); _FinalStage addDocuments(RerankRequestDocumentsItem documents); _FinalStage addAllDocuments(List documents); _FinalStage topN(Optional topN); _FinalStage topN(Integer topN); _FinalStage rankFields(Optional> rankFields); _FinalStage rankFields(List rankFields); _FinalStage returnDocuments(Optional returnDocuments); _FinalStage returnDocuments(Boolean returnDocuments); _FinalStage maxChunksPerDoc(Optional maxChunksPerDoc); _FinalStage maxChunksPerDoc(Integer maxChunksPerDoc); } @JsonIgnoreProperties(ignoreUnknown = true) public static final class Builder implements QueryStage, _FinalStage { private String query; private Optional maxChunksPerDoc = Optional.empty(); private Optional returnDocuments = Optional.empty(); private Optional> rankFields = Optional.empty(); private Optional topN = Optional.empty(); private List documents = new ArrayList<>(); private Optional model = Optional.empty(); @JsonAnySetter private Map additionalProperties = new HashMap<>(); private Builder() {} @java.lang.Override public Builder from(RerankRequest other) { model(other.getModel()); query(other.getQuery()); documents(other.getDocuments()); topN(other.getTopN()); rankFields(other.getRankFields()); returnDocuments(other.getReturnDocuments()); maxChunksPerDoc(other.getMaxChunksPerDoc()); return this; } /** *

The search query

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override @JsonSetter("query") public _FinalStage query(String query) { this.query = query; return this; } /** *

The maximum number of chunks to produce internally from a document

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage maxChunksPerDoc(Integer maxChunksPerDoc) { this.maxChunksPerDoc = Optional.of(maxChunksPerDoc); return this; } @java.lang.Override @JsonSetter(value = "max_chunks_per_doc", nulls = Nulls.SKIP) public _FinalStage maxChunksPerDoc(Optional maxChunksPerDoc) { this.maxChunksPerDoc = maxChunksPerDoc; return this; } /** *
    *
  • If false, returns results without the doc text - the api will return a list of {index, relevance score} where index is inferred from the list passed into the request.
  • *
  • If true, returns results with the doc text passed in - the api will return an ordered list of {index, text, relevance score} where index + text refers to the list passed into the request.
  • *
* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage returnDocuments(Boolean returnDocuments) { this.returnDocuments = Optional.of(returnDocuments); return this; } @java.lang.Override @JsonSetter(value = "return_documents", nulls = Nulls.SKIP) public _FinalStage returnDocuments(Optional returnDocuments) { this.returnDocuments = returnDocuments; return this; } /** *

If a JSON object is provided, you can specify which keys you would like to have considered for reranking. The model will rerank based on order of the fields passed in (i.e. rank_fields=['title','author','text'] will rerank using the values in title, author, text sequentially. If the length of title, author, and text exceeds the context length of the model, the chunking will not re-consider earlier fields). If not provided, the model will use the default text field for ranking.

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage rankFields(List rankFields) { this.rankFields = Optional.of(rankFields); return this; } @java.lang.Override @JsonSetter(value = "rank_fields", nulls = Nulls.SKIP) public _FinalStage rankFields(Optional> rankFields) { this.rankFields = rankFields; return this; } /** *

The number of most relevant documents or indices to return, defaults to the length of the documents

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage topN(Integer topN) { this.topN = Optional.of(topN); return this; } @java.lang.Override @JsonSetter(value = "top_n", nulls = Nulls.SKIP) public _FinalStage topN(Optional topN) { this.topN = topN; return this; } /** *

A list of document objects or strings to rerank. * If a document is provided the text fields is required and all other fields will be preserved in the response.

*

The total max chunks (length of documents * max_chunks_per_doc) must be less than 10000.

*

We recommend a maximum of 1,000 documents for optimal endpoint performance.

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage addAllDocuments(List documents) { this.documents.addAll(documents); return this; } /** *

A list of document objects or strings to rerank. * If a document is provided the text fields is required and all other fields will be preserved in the response.

*

The total max chunks (length of documents * max_chunks_per_doc) must be less than 10000.

*

We recommend a maximum of 1,000 documents for optimal endpoint performance.

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage addDocuments(RerankRequestDocumentsItem documents) { this.documents.add(documents); return this; } @java.lang.Override @JsonSetter(value = "documents", nulls = Nulls.SKIP) public _FinalStage documents(List documents) { this.documents.clear(); this.documents.addAll(documents); return this; } /** *

The identifier of the model to use, one of : rerank-english-v3.0, rerank-multilingual-v3.0, rerank-english-v2.0, rerank-multilingual-v2.0

* @return Reference to {@code this} so that method calls can be chained together. */ @java.lang.Override public _FinalStage model(String model) { this.model = Optional.of(model); return this; } @java.lang.Override @JsonSetter(value = "model", nulls = Nulls.SKIP) public _FinalStage model(Optional model) { this.model = model; return this; } @java.lang.Override public RerankRequest build() { return new RerankRequest( model, query, documents, topN, rankFields, returnDocuments, maxChunksPerDoc, additionalProperties); } } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy