Implementation:Cohere ai Cohere python ChatSearchResult Model
| Knowledge Sources | |
|---|---|
| Domains | SDK, Search, RAG |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
ChatSearchResult is a Pydantic model representing a single search result returned from a connector during retrieval-augmented generation (RAG) in the Cohere chat API.
Description
The ChatSearchResult model captures the outcome of a document search performed by a connector. It includes the search query that was issued, the connector that produced the result, the list of document IDs that were found, and optional error handling information. This model is part of the RAG pipeline where the Cohere API queries external data sources to ground generated responses with real documents.
Key characteristics:
- Contains a reference to the originating search_query via
ChatSearchQuery. - Contains a reference to the connector that performed the search via
ChatSearchResultConnector. - Returns a list of document_ids that matched the query.
- Provides an optional error_message if the search failed.
- Includes a continue_on_failure flag to control whether the chat request should proceed even if this connector fails.
Usage
Use ChatSearchResult when processing search results from the Cohere chat API's RAG pipeline. This model appears in chat responses that include connector-based document retrieval, allowing you to inspect which documents were found, which connector was used, and whether any errors occurred during the search.
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/types/chat_search_result.py
Signature
class ChatSearchResult(UncheckedBaseModel):
search_query: typing.Optional[ChatSearchQuery] = None
connector: ChatSearchResultConnector = pydantic.Field()
document_ids: typing.List[str] = pydantic.Field()
error_message: typing.Optional[str] = pydantic.Field(default=None)
continue_on_failure: typing.Optional[bool] = pydantic.Field(default=None)
Import
from cohere.types import ChatSearchResult
I/O Contract
Fields
| Field | Type | Required | Description |
|---|---|---|---|
search_query |
Optional[ChatSearchQuery] |
No | The search query that was used to retrieve documents. |
connector |
ChatSearchResultConnector |
Yes | The connector from which this result comes from. |
document_ids |
List[str] |
Yes | Identifiers of documents found by this search query. |
error_message |
Optional[str] |
No | An error message if the search failed. |
continue_on_failure |
Optional[bool] |
No | Whether a chat request should continue or not if the request to this connector fails. |
Usage Examples
from cohere.types import ChatSearchResult
# ChatSearchResult is typically returned as part of a chat response
response = client.chat(
message="What are the latest quarterly results?",
connectors=[{"id": "web-search"}],
)
# Access search results from the response
for result in response.search_results:
print(f"Connector: {result.connector}")
print(f"Documents found: {result.document_ids}")
if result.error_message:
print(f"Error: {result.error_message}")
if result.search_query:
print(f"Query used: {result.search_query}")