Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions .fern/metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"optional": true
}
},
"extra_dev_dependencies": {
"pydantic": ">=2.0.0,<2.14.0"
},
"improved_imports": true,
"pydantic_config": {
"frozen": false,
Expand Down Expand Up @@ -100,10 +103,10 @@
}
]
},
"originGitCommit": "2bfdfa67e2f98426451cf784a8f798e6c9272b9b",
"originGitCommit": "c39b7388c89804b40d40b481f5338b5a39c93a32",
"originGitCommitIsDirty": false,
"invokedBy": "ci",
"requestedVersion": "7.2.0",
"requestedVersion": "7.3.0",
"ciProvider": "github",
"sdkVersion": "7.2.0"
"sdkVersion": "7.3.0"
}
8 changes: 7 additions & 1 deletion .fern/replay.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1,516 changes: 867 additions & 649 deletions poetry.lock

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ dynamic = ["version"]

[tool.poetry]
name = "cohere"
version = "7.2.0"
version = "7.3.0"
description = ""
readme = "README.md"
authors = []
Expand Down Expand Up @@ -58,6 +58,7 @@ pytest-xdist = "^3.6.1"
python-dateutil = "^2.9.0"
types-python-dateutil = "^2.9.0.20240316"
urllib3 = ">=2.6.3,<3.0.0"
pydantic = ">=2.0.0,<2.14.0"
ruff = "==0.11.5"

[tool.pytest.ini_options]
Expand Down
31 changes: 22 additions & 9 deletions reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1510,8 +1510,8 @@ client.embed(
"hello",
"goodbye"
],
model="embed-v4.0",
input_type="classification",
model="embed-v5.0-fast",
input_type="search_document",
)

```
Expand Down Expand Up @@ -3025,8 +3025,8 @@ client.v2.embed(
"hello",
"goodbye"
],
model="embed-v4.0",
input_type="classification",
model="embed-v5.0-fast",
input_type="search_document",
embedding_types=[
"float"
],
Expand Down Expand Up @@ -3107,7 +3107,7 @@ For **Embed v4.0 and newer** models, there is no limit on the number of images p
**output_dimension:** `typing.Optional[int]`

The number of dimensions of the output embedding. This is only available for `embed-v4` and newer models.
Possible values are `256`, `512`, `1024`, and `1536`. The default is `1536`.
For supported dimensions, please refer to the [Embed models](https://docs.cohere.com/docs/cohere-embed) page.

</dd>
</dl>
Expand Down Expand Up @@ -3193,7 +3193,7 @@ This endpoint takes in a query and a list of texts and produces an ordered array
<dd>

```python
from cohere import Client
from cohere import Client, RerankRelevantSpans
from cohere.environment import ClientEnvironment

client = Client(
Expand All @@ -3202,16 +3202,21 @@ client = Client(
)

client.v2.rerank(
model="rerank-v4.0-pro",
model="rerank-v5.0-pro",
query="What is the capital of the United States?",
documents=[
"Carson City is the capital city of the American state of Nevada.",
"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean. Its capital is Saipan.",
"Capitalization or capitalisation in English grammar is the use of a capital letter at the start of a word. English usage varies from capitalization in other languages.",
"Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) is the capital of the United States. It is a federal district.",
"Capital punishment has existed in the United States since beforethe United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states."
"Capital gains are profits from the sale of an asset such as stocks or real estate. In the United States, long-term capital gains are taxed at lower rates than ordinary income."
],
top_n=3,
relevant_spans=RerankRelevantSpans(
mode="enabled",
threshold=0.1,
max_spans=3,
),
)

```
Expand All @@ -3228,7 +3233,7 @@ client.v2.rerank(
<dl>
<dd>

**model:** `str` — The identifier of the model to use, eg `rerank-v3.5`.
**model:** `str` — The identifier of the model to use, eg `rerank-v5.0-pro`.

</dd>
</dl>
Expand Down Expand Up @@ -3275,6 +3280,14 @@ For optimal performance we recommend against sending more than 1,000 documents i
<dl>
<dd>

**relevant_spans:** `typing.Optional[RerankRelevantSpans]`

</dd>
</dl>

<dl>
<dd>

**priority:** `typing.Optional[int]` — Controls how early the request is handled. Lower numbers indicate higher priority (default: 0, the highest). When the system is under load, higher-priority requests are processed first and are the least likely to be dropped.

</dd>
Expand Down
9 changes: 9 additions & 0 deletions src/cohere/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@
ParseTextBlock,
ParseTextContentBlock,
RerankDocument,
RerankRelevantSpanResponse,
RerankRelevantSpans,
RerankRelevantSpansMode,
RerankRequestDocumentsItem,
RerankResponse,
RerankResponseResultsItem,
Expand Down Expand Up @@ -572,6 +575,9 @@
"ParseTextBlock": ".types",
"ParseTextContentBlock": ".types",
"RerankDocument": ".types",
"RerankRelevantSpanResponse": ".types",
"RerankRelevantSpans": ".types",
"RerankRelevantSpansMode": ".types",
"RerankRequestDocumentsItem": ".types",
"RerankResponse": ".types",
"RerankResponseResultsItem": ".types",
Expand Down Expand Up @@ -934,6 +940,9 @@ def __dir__():
"ParseTextBlock",
"ParseTextContentBlock",
"RerankDocument",
"RerankRelevantSpanResponse",
"RerankRelevantSpans",
"RerankRelevantSpansMode",
"RerankRequestDocumentsItem",
"RerankResponse",
"RerankResponseResultsItem",
Expand Down
8 changes: 4 additions & 4 deletions src/cohere/base_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1147,8 +1147,8 @@ def embed(
)
client.embed(
texts=["hello", "goodbye"],
model="embed-v4.0",
input_type="classification",
model="embed-v5.0-fast",
input_type="search_document",
)
"""
_response = self._raw_client.embed(
Expand Down Expand Up @@ -2747,8 +2747,8 @@ async def embed(
async def main() -> None:
await client.embed(
texts=["hello", "goodbye"],
model="embed-v4.0",
input_type="classification",
model="embed-v5.0-fast",
input_type="search_document",
)


Expand Down
4 changes: 2 additions & 2 deletions src/cohere/core/client_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ def get_headers(self) -> typing.Dict[str, str]:
import platform

headers: typing.Dict[str, str] = {
"User-Agent": "cohere/7.2.0",
"User-Agent": "cohere/7.3.0",
"X-Fern-Language": "Python",
"X-Fern-Runtime": f"python/{platform.python_version()}",
"X-Fern-Platform": f"{platform.system().lower()}/{platform.release()}",
"X-Fern-SDK-Name": "cohere",
"X-Fern-SDK-Version": "7.2.0",
"X-Fern-SDK-Version": "7.3.0",
**(self.get_custom_headers() or {}),
}
if self._client_name is not None:
Expand Down
9 changes: 9 additions & 0 deletions src/cohere/types/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,9 @@
from .parse_text_block import ParseTextBlock
from .parse_text_content_block import ParseTextContentBlock
from .rerank_document import RerankDocument
from .rerank_relevant_span_response import RerankRelevantSpanResponse
from .rerank_relevant_spans import RerankRelevantSpans
from .rerank_relevant_spans_mode import RerankRelevantSpansMode
from .rerank_request_documents_item import RerankRequestDocumentsItem
from .rerank_response import RerankResponse
from .rerank_response_results_item import RerankResponseResultsItem
Expand Down Expand Up @@ -444,6 +447,9 @@
"ParseTextBlock": ".parse_text_block",
"ParseTextContentBlock": ".parse_text_content_block",
"RerankDocument": ".rerank_document",
"RerankRelevantSpanResponse": ".rerank_relevant_span_response",
"RerankRelevantSpans": ".rerank_relevant_spans",
"RerankRelevantSpansMode": ".rerank_relevant_spans_mode",
"RerankRequestDocumentsItem": ".rerank_request_documents_item",
"RerankResponse": ".rerank_response",
"RerankResponseResultsItem": ".rerank_response_results_item",
Expand Down Expand Up @@ -727,6 +733,9 @@ def __dir__():
"ParseTextBlock",
"ParseTextContentBlock",
"RerankDocument",
"RerankRelevantSpanResponse",
"RerankRelevantSpans",
"RerankRelevantSpansMode",
"RerankRequestDocumentsItem",
"RerankResponse",
"RerankResponseResultsItem",
Expand Down
36 changes: 36 additions & 0 deletions src/cohere/types/rerank_relevant_span_response.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# This file was auto-generated by Fern from our API Definition.

import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2
from ..core.unchecked_base_model import UncheckedBaseModel


class RerankRelevantSpanResponse(UncheckedBaseModel):
"""
A stretch of a document that the model found relevant to the query, returned when context compression is enabled through `relevant_spans`.
"""

start: int = pydantic.Field()
"""
The position of the span's first character in the document, counted in Unicode codepoints.
"""

end: int = pydantic.Field()
"""
The position just past the span's last character, counted in Unicode codepoints, so the span covers `[start, end)` of the document.
"""

score: float = pydantic.Field()
"""
How relevant the span is to the query, in the range `[0, 1]`. Only spans reaching the requested `threshold` are returned.
"""

if IS_PYDANTIC_V2:
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow") # type: ignore # Pydantic v2
else:

class Config:
smart_union = True
extra = pydantic.Extra.allow
37 changes: 37 additions & 0 deletions src/cohere/types/rerank_relevant_spans.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This file was auto-generated by Fern from our API Definition.

import typing

import pydantic
from ..core.pydantic_utilities import IS_PYDANTIC_V2
from ..core.unchecked_base_model import UncheckedBaseModel
from .rerank_relevant_spans_mode import RerankRelevantSpansMode


class RerankRelevantSpans(UncheckedBaseModel):
"""
When enabled, the API response will include the relevant spans of each document that contributed to its rank. This feature is only supported for Rerank v5 and newer models.
"""

mode: RerankRelevantSpansMode = pydantic.Field()
"""
One of `"enabled"` or `"disabled"`. Controls whether relevant spans will be returned in the API response.
"""

threshold: typing.Optional[float] = pydantic.Field(default=None)
"""
Only spans with a relevance score higher than the specified threshold value will be included in the response. Defaults to `0.1`.
"""

max_spans: typing.Optional[int] = pydantic.Field(default=None)
"""
The maximum number of relevant spans to include per document. If not set, all relevant spans will be returned.
"""

if IS_PYDANTIC_V2:
model_config: typing.ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(extra="allow") # type: ignore # Pydantic v2
else:

class Config:
smart_union = True
extra = pydantic.Extra.allow
5 changes: 5 additions & 0 deletions src/cohere/types/rerank_relevant_spans_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file was auto-generated by Fern from our API Definition.

import typing

RerankRelevantSpansMode = typing.Union[typing.Literal["enabled", "disabled"], typing.Any]
Loading
Loading