Use the Passage Retrieval API
Use the Passage Retrieval API
The Passage Retrieval API (PR API) allows developers to retrieve specific sections of text (passages) from documents stored in Coveo. This enables efficient retrieval of ranked text data for various use cases, including enhancing large language models (LLMs).
The PR API offers the following key features:
-
Integration with Coveo Search API
The PR API is built upon the existing Coveo Search API infrastructure, allowing you to leverage your existing query pipelines.
-
Query pipelines configuration
This API supports many query pipeline configurations, allowing you to customize the behavior of the PR API. However, some features aren’t supported or have limitations (see Query pipeline feature support).
-
This API uses Coveo’s advanced ML models, such as the Automatic Relevance Tuning (ART) model, to dynamically adjust and improve search relevance.
-
Contextual passage retrieval
It’s specifically designed to return contextual pieces of information (passages) from documents enhancing the accuracy and relevance of responses generated by LLMs.
This article explains how to use the Passage Retrieval API to retrieve text passages from a Coveo index.
Prerequisites
To use the Passage Retrieval API, make sure:
-
You’ve created a Passage Retrieval (CPR) model and associated it with a query pipeline.
-
The query pipeline that’s associated with the CPR model must also be associated with a Semantic Encoder (SE) model.
-
The privileges for your CPR model include the following:
Service Domain Required access level Machine Learning
Allow content preview
Enable
Limitations
-
Due to the amount of processing required for embeddings, the CPR model is subject to embedding limits.
-
Performance is directly related to the number of documents and their average size. For example, doubling the average passages per document may reduce the queries per second (QPS) rate by half.
-
Supported authentication methods are:
-
OAuth 2.0
-
-
By default, the CPR model supports only English content.
Coveo offers beta support for content retrieval in languages other than English. Learn more about multilingual content retrieval and answer generation.
Query pipeline feature support
The Passage Retrieval API supports many query pipeline features, but some aren’t supported or have limitations.
| Feature | Support status | Notes |
|---|---|---|
Partial |
Conditions based on |
|
Not supported |
||
Supported |
||
Partial |
|
|
Supported |
Includes Featured results and Ranking expressions. |
|
Partial |
The only supported model is Automatic Relevance Tuning (ART). |
|
Partial |
|
Request endpoint
To use the Passage Retrieval API, send a POST request to the following endpoint:
POST https://<MyOrganizationId>.org.coveo.com/rest/search/v3/passages/retrieve HTTP/1.1
Content-Type: application/json
Accept: application/json
Authorization: Bearer <MyAccessToken>
Request payload
The following example shows the payload to retrieve passages from a Coveo index:
{
"query": "What are the benefits of using solar energy?",
"filter": "@source==\"acme\"",
"additionalFields": ["clickableuri"],
"maxPassages": 5,
"searchHub": "Main",
"localization": {
"locale": "en-CA",
"timezone": "America/Montreal"
},
"context": {
"userAgeRange": "25-35",
"userRoles": ["PremiumCustomer", "ProductReviewer"]
}
}
Details
query (string, required): The basic query expression, typically the keywords entered by the end user in a query box. |
|
filter (string): The filter expression to apply to the query. This expression is used to restrict the search to a specific source or document type. |
|
additionalFields (string[]): The additional fields to include in the response, maximum of 20 fields. The identifier of the document (primaryid) is always returned in the response, but you can choose to include metadata from other document fields. |
|
maxPassages (number): The maximum number of passages to retrieve. Minimum is 1, maximum is 20. The passages are sorted by relevance score in descending order, so the first passage in the response is the most relevant one. |
|
searchHub (string, required): The origin level 1 of the request, typically the identifier of the graphical search interface from which the request originates. Required in the payload or in the authentication token. See About the search hub. |
|
localization (object, required): localization parameters |
|
locale (string, required): The locale for the search. |
|
timezone (string): The tz database identifier of the user’s time zone. |
|
context (object): The custom context information to send along with the request. Consists of key-value pairs where the key is a string and the value is a string or an array of strings. |
|
|
For more details, see the Passage Retrieval API reference. |
Response payload
The following example shows a response payload from the Passage Retrieval API:
|
|
Note
The total response size is limited to 540 KB. If the response size exceeds the maximum, the Passage Retrieval API returns an error message. |
{
"items": [
{
"text": "Solar energy has several benefits including reducing electricity bills, [...]",
"relevanceScore": 0.95,
"document": {
"title": "The Benefits of Solar Energy",
"primaryid": "GAYEG6LHNB2DQ4LLNBKVEUSHKUXDCMZWGEZS4ZDFMZQXK3DU",
"clickableuri": "https://example.com/search/document-solar-energy"
}
}
],
"responseId": "c0857557-5579-4f5e-8958-9befd7d1d4a8"
}
Details
items (object[]): The array of passages. |
|
text (string): Text content of the passage. |
|
relevanceScore (number): A measure of how relevant a passage is to the query. The higher the value, the higher the relevance. The score computation is based on cosine similarity between the passage and the query. NOTE: The computation logic may change in the future. |
|
document (object): The document that contains this passage. By default, it includes only the title and primary ID of the document. If you specify additional fields in the request payload, they’re included here as well. |
|
responseId (string): A unique identifier for the response. You can use it to track the response in logs or for debugging. |
|
|
For more details, see the Passage Retrieval API reference. |