From 35d2443be24ca8b40c9af32502451bd59b2f2bf4 Mon Sep 17 00:00:00 2001 From: Trent Fowler Date: Tue, 19 Nov 2024 14:27:34 -0700 Subject: [PATCH 1/7] rerank 3.5 updates. --- fern/pages/models/rerank-2.mdx | 13 ++++++------ .../reranking/reranking-best-practices.mdx | 21 +++++++++++++------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/fern/pages/models/rerank-2.mdx b/fern/pages/models/rerank-2.mdx index 069869dc..a8aa9548 100644 --- a/fern/pages/models/rerank-2.mdx +++ b/fern/pages/models/rerank-2.mdx @@ -13,12 +13,13 @@ updatedAt: "Mon Apr 08 2024 17:42:11 GMT+0000 (Coordinated Universal Time)" --- Rerank models sort text inputs by semantic relevance to a specified query. They are often used to sort search results returned from an existing search solution. Learn more about using Rerank in the [best practices guide](/docs/reranking-best-practices). -| Latest Model | Description | Modality | Max Tokens | Endpoints | -| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ---------|------------|-------------------| -| `rerank-english-v3.0` | A model that allows for re-ranking English Language documents and semi-structured data (JSON). This model has a context length of 4096 tokens. | Text | N/A | [Rerank](/reference/rerank) | -| `rerank-multilingual-v3.0` | A model for documents and semi-structure data (JSON) that are not in English. Supports the same languages as `embed-multilingual-v3.0`. This model has a context length of 4096 tokens.| Text | N/A | [Rerank](/reference/rerank) | -| `rerank-english-v2.0` | A model that allows for re-ranking English language documents. This model has a context length of 512 tokens. | Text | N/A | [Rerank](/reference/rerank) | -| `rerank-multilingual-v2.0` | A model for documents that are not in English. Supports the same languages as `embed-multilingual-v3.0`. This model has a context length of 512 tokens. | Text | N/A | [Rerank](/reference/rerank) | +| Latest Model | Description | Modality | Max Tokens | Endpoints | +| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|------------|-------------------| +| `rerank-english-v3.5` | A model for documents and semi-structured data (JSON). State-of-the-art performance in English and non-English languages; supports the same languages as embed-multilingual-v3.0. This model has a context length of 4096 tokens | Text | N/A | [Rerank](/reference/rerank) | +| `rerank-english-v3.0` | A model that allows for re-ranking English Language documents and semi-structured data (JSON). This model has a context length of 4096 tokens. | Text | N/A | [Rerank](/reference/rerank) | +| `rerank-multilingual-v3.0` | A model for documents and semi-structure data (JSON) that are not in English. Supports the same languages as `embed-multilingual-v3.0`. This model has a context length of 4096 tokens. | Text | N/A | [Rerank](/reference/rerank) | +| `rerank-english-v2.0` | A model that allows for re-ranking English language documents. This model has a context length of 512 tokens. | Text | N/A | [Rerank](/reference/rerank) | +| `rerank-multilingual-v2.0` | A model for documents that are not in English. Supports the same languages as `embed-multilingual-v3.0`. This model has a context length of 512 tokens. | Text | N/A | [Rerank](/reference/rerank) | For each document included in a request, Rerank combines the tokens from the query with the tokens from the document and the combined total counts toward the context limit for a single document. If the combined number of tokens from the query and a given document exceeds the model’s context length for a single document, the document will automatically get chunked and processed in multiple inferences. See our [best practice guide](/docs/reranking-best-practices) for more info about formatting documents for the Rerank endpoint. diff --git a/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx b/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx index 1ba0bb92..6a7e80f1 100644 --- a/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx +++ b/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx @@ -13,6 +13,15 @@ updatedAt: 'Thu May 30 2024 15:16:00 GMT+0000 (Coordinated Universal Time)' In the following two tables, you'll find recommendations for getting the best Rerank performance, organized by model family. +### Rerank-v3.5 + +| Constraint | Minimum | Maximum | Default Value | +| ----------------------------- | ------- | ------------------------------------------------------------------------------------------------------- | :------------ | +| Number of Documents | 1 | 10,000 | N/A | +| Max Number of Chunks | 1 | N/A | 4000 | +| Number of Tokens per Document | 1 | N/A (see [below ](/docs/reranking-best-practices#document-chunking)for more info) | N/A | +| Number of Tokens per Query | 1 | 2048 | N/A | + ### Rerank-v3.0 | Constraint | Minimum | Maximum | Default Value | @@ -33,11 +42,11 @@ In the following two tables, you'll find recommendations for getting the best Re ## Document Chunking -For `rerank-v3.0`, the model breaks documents into 4094 token chunks. For example, if your query is 100 tokens and your document is 10,000 tokens, your document will be broken into the following chunks: +For rerank-v3.0 and rerank-v3.5, the model breaks documents into 4096 token chunks. For example, if your query is 100 tokens and your document is 10,000 tokens, your document will be broken into the following chunks: 1. `relevance_score_1 = ` -2. `relevance_score_2 = ` -3. `relevance_score_3 = ` +2. `relevance_score_2 = ` +3. `relevance_score_3 = ` 4. `relevance_score = max(relevance_score_1, relevance_score_2, relevance_score_3)` If you would like more control over how chunking is done, we recommend that you chunk your documents yourself. @@ -54,15 +63,15 @@ If `Number of documents * max_chunks_per_doc` exceeds `1000`, the endpoint will When using `rerank-v2.0`, the endpoint will throw an error if the user tries to pass more than 10,000 documents at a time. The maximum number of documents that can be passed to the endpoint is calculated with the following inequality: `Number of documents * max_chunks_per_doc >10,000`. -If `Number of documents * max_chunks_per_doc` exceeds `10,000`, the endpoint will return an error. By default, the `max_chunks_per_doc` is set to `10` for `rerank-v2.0` models; given that the model has a context length of 512, the maximum number of tokens for each call would be 5,120,000. +If `Number of documents * max_chunks_per_doc` exceeds `1000`, the endpoint will return an error. By default, the `max_chunks_per_doc` is set to `1` for `rerank-v3.0` models; given that the model has a context length of 4096, the maximum number of tokens for each call would be 4,096,000. ## Queries -Our `rerank-v3.0` models are trained with a context length of 4096 tokens. The model takes into account both the input from the query and document. If your query is larger than 2048 tokens, it will be truncated to the first 2048 tokens. For v2.0 models, if your query is larger than 256 tokens, it will be truncated to the first 256 tokens. +Our `rerank-v3.0` and `rerank-v3.5` models are trained with a context length of 4096 tokens. The model takes into account both the input from the query and document. If your query is larger than 2048 tokens, it will be truncated to the first 2048 tokens. For `rerank-v2.0` models, if your query is larger than 256 tokens, it will be truncated to the first 256 tokens ## Semi-Structured Data Support -Our `rerank-v3.0` models support semi-structured data reranking through a list of JSON objects. The `rank_fields` parameter will default to a field parameter called `text` unless otherwise specified. If the `rank_fields` parameter is unspecified _and_ none of your JSON objects have a `text` field, the endpoint will return an error. +Our rerank-v3.0 models support semi-structured data reranking through a list of JSON objects. The rank_fields parameter will default to a field parameter called text unless otherwise specified. If the rank_fields parameter is unspecified and none of your JSON objects have a text field, the endpoint will return an error. ```json JSON [ From adc4f573bfd3f3b2cb7e740d440073cebd69b81a Mon Sep 17 00:00:00 2001 From: Trent Fowler Date: Wed, 20 Nov 2024 14:21:23 -0700 Subject: [PATCH 2/7] Found a few typos. --- .../text-embeddings/reranking/reranking-best-practices.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx b/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx index 6a7e80f1..543a3f4a 100644 --- a/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx +++ b/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx @@ -71,7 +71,7 @@ Our `rerank-v3.0` and `rerank-v3.5` models are trained with a context length o ## Semi-Structured Data Support -Our rerank-v3.0 models support semi-structured data reranking through a list of JSON objects. The rank_fields parameter will default to a field parameter called text unless otherwise specified. If the rank_fields parameter is unspecified and none of your JSON objects have a text field, the endpoint will return an error. +Our rerank-v3.0 models support semi-structured data reranking through a list of JSON objects. The `rank_fields` parameter will default to a field parameter called `text` unless otherwise specified. If the `rank_fields` parameter is unspecified and none of your JSON objects have a `text` field, the endpoint will return an error. ```json JSON [ From e25c4a49c2b6811f22a2e016eb44e3973f3e321e Mon Sep 17 00:00:00 2001 From: Trent Fowler Date: Tue, 26 Nov 2024 12:57:00 -0700 Subject: [PATCH 3/7] Minor word changes. --- .../text-embeddings/reranking/reranking-best-practices.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx b/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx index 543a3f4a..5aeb252f 100644 --- a/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx +++ b/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx @@ -55,7 +55,7 @@ If you would like more control over how chunking is done, we recommend that you ### Rerank-v3.0 Models -When using `rerank-v3.0` models, the endpoint will throw an error if the user tries to pass more than 1000 documents at a time. The maximum number of documents that can be passed to the endpoint is calculated with the following inequality: `Number of documents * max_chunks_per_doc >1000`. +When using `rerank-v3.0` models, the endpoint will throw an error if the user attempts to pass more than 1000 documents at a time. The maximum number of documents that can be passed to the endpoint is calculated with the following inequality: `Number of documents * max_chunks_per_doc >1000`. If `Number of documents * max_chunks_per_doc` exceeds `1000`, the endpoint will return an error. By default, the `max_chunks_per_doc` is set to `1` for `rerank-v3.0` models; given that the model has a context length of 4096, the maximum number of tokens for each call would be 4,096,000. From 5be09ba1cd3860e326a266084670c48d2bb7908e Mon Sep 17 00:00:00 2001 From: Trent Fowler Date: Fri, 29 Nov 2024 13:41:15 -0700 Subject: [PATCH 4/7] Adding rerank 3.5 to the main model page. --- fern/pages/models/models.mdx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/fern/pages/models/models.mdx b/fern/pages/models/models.mdx index 6407c467..45868f51 100644 --- a/fern/pages/models/models.mdx +++ b/fern/pages/models/models.mdx @@ -104,13 +104,14 @@ In this table, we provide some important context for using Cohere Embed models o The Rerank model can improve created models by re-organizing their results based on certain parameters. This can be used to improve search algorithms. -| Model Name | Description | Modalities | Context Length | Endpoints | -| -------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------- | ---------------|---------------------------- | -| `rerank-english-v3.0` | A model that allows for re-ranking English Language documents and semi-structured data (JSON). This model has a context length of 4096 tokens. | Text | 4k | [Rerank](/reference/rerank) | -| `rerank-multilingual-v3.0` | A model for documents and semi-structure data (JSON) that are not in English. Supports the same languages as embed-multilingual-v3.0. This model has a context length of 4096 tokens. | Text | 4k | [Rerank](/reference/rerank) | -| | | | | | -| `rerank-english-v2.0` | A model that allows for re-ranking English language documents. | Text | 512 | [Rerank](/reference/rerank) | -| `rerank-multilingual-v2.0` | A model for documents that are not in English. Supports the same languages as `embed-multilingual-v3.0`. | Text | 512 | [Rerank](/reference/rerank) | +| Latest Model | Description | Modality | Max Tokens | Endpoints | +| -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|------------|-------------------| +| `rerank-english-v3.5` | A model for documents and semi-structured data (JSON). State-of-the-art performance in English and non-English languages; supports the same languages as embed-multilingual-v3.0. This model has a context length of 4096 tokens | Text | N/A | [Rerank](/reference/rerank) | +| `rerank-english-v3.0` | A model that allows for re-ranking English Language documents and semi-structured data (JSON). This model has a context length of 4096 tokens. | Text | N/A | [Rerank](/reference/rerank) | +| `rerank-multilingual-v3.0` | A model for documents and semi-structure data (JSON) that are not in English. Supports the same languages as `embed-multilingual-v3.0`. This model has a context length of 4096 tokens. | Text | N/A | [Rerank](/reference/rerank) | +| `rerank-english-v2.0` | A model that allows for re-ranking English language documents. This model has a context length of 512 tokens. | Text | N/A | [Rerank](/reference/rerank) | +| `rerank-multilingual-v2.0` | A model for documents that are not in English. Supports the same languages as `embed-multilingual-v3.0`. This model has a context length of 512 tokens. | Text | N/A | [Rerank](/reference/rerank) | + ### Using Rerank Models on Different Platforms From e235b92cf427f4bd34322bda9e4c82108b76037a Mon Sep 17 00:00:00 2001 From: Trent Fowler Date: Sun, 1 Dec 2024 13:08:34 -0700 Subject: [PATCH 5/7] Making a few changes based off of Michael's branch 266. --- .../text-embeddings/reranking/overview.mdx | 8 +- .../reranking/reranking-best-practices.mdx | 20 +-- .../v2/text-embeddings/reranking/overview.mdx | 153 ++++++++++-------- 3 files changed, 101 insertions(+), 80 deletions(-) diff --git a/fern/pages/text-embeddings/reranking/overview.mdx b/fern/pages/text-embeddings/reranking/overview.mdx index 89523f60..ad64c042 100644 --- a/fern/pages/text-embeddings/reranking/overview.mdx +++ b/fern/pages/text-embeddings/reranking/overview.mdx @@ -4,7 +4,7 @@ slug: "docs/overview" hidden: false -description: "This page describes how Cohere's ReRank models work." +description: "This page describes how Cohere's Rerank models work." image: "../../../assets/images/f1cc130-cohere_meta_image.jpg" keywords: "Cohere, reranking models, large language models" @@ -36,7 +36,7 @@ docs = [ "Charlotte Amalie is the capital and largest city of the United States Virgin Islands. It has about 20,000 people. The city is on the island of Saint Thomas.", "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. The President of the USA and many major national government offices are in the territory. This makes it the political center of the United States of America.", "Capital punishment (the death penalty) has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states. The federal government (including the United States military) also uses capital punishment."] -results = co.rerank(model="rerank-english-v3.0", query=query, documents=docs, top_n=5, return_documents=True) +results = co.rerank(model="rerank-v3.5", query=query, documents=docs, top_n=5, return_documents=True) ``` **Response** @@ -107,7 +107,7 @@ docs = [ {"Title":"The Capital of United States Virgin Islands","Content":"Charlotte Amalie is the capital and largest city of the United States Virgin Islands. It has about 20,000 people. The city is on the island of Saint Thomas."}, {"Title":"Washington D.C.","Content":"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. The President of the USA and many major national government offices are in the territory. This makes it the political center of the United States of America."}, {"Title":"Capital Punishment in the US","Content":"Capital punishment (the death penalty) has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states. The federal government (including the United States military) also uses capital punishment."}] -results = co.rerank(model="rerank-english-v3.0", query=query, documents=docs, rank_fields=['Title','Content'],top_n=5, return_documents=True) +results = co.rerank(model="rerank-v3.5", query=query, documents=docs, rank_fields=['Title','Content'],top_n=5, return_documents=True) ``` @@ -172,7 +172,7 @@ In the `docs` parameter, we are passing in a list of objects which have the key ## Multilingual Reranking -Cohere offers a multilingual model, `rerank-multilingual-v3.0`. Please note that performance may vary across languages. The model is trained on the following languages: +Cohere's `rerank-v3.5` and `rerank-multilingual-v3.0` models have been trained for performance across a variety of languages. Please note that performance may vary across languages. The model is trained on the following languages: | ISO Code | Language Name | | -------- | -------------- | diff --git a/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx b/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx index 5aeb252f..61867716 100644 --- a/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx +++ b/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx @@ -76,16 +76,16 @@ Our rerank-v3.0 models support semi-structured data reranking through a list o ```json JSON [ { - "Title":"How to fix a dishwasher" - "Author":"John Smith" - "Date":"August 1st 2023" + "Title": "How to fix a dishwasher", + "Author": "John Smith", + "Date": "August 1st 2023", "Content": "Fixing a dishwasher depends on the specific problem you're facing. Here are some common issues and their potential solutions:...." }, { - "Title":"How to fix a leaky sink" - "Date":"July 25th 2024" + "Title": "How to fix a leaky sink", + "Date": "July 25th 2024", "Content": "Fixing a leaky sink will depend on the source of the leak. Here are general steps you can take to address common types of sink leaks:....." - },..... + } ] ``` @@ -96,10 +96,10 @@ Looking at the example above, passing in `rank_fields=["Title","Content"]` would The most important output from the [Rerank API endpoint](/reference/rerank-1) is the absolute rank exposed in the response object. The score is query dependent, and could be higher or lower depending on the query and passages sent in. In the example below, what matters is that Ottawa is more relevant than Toronto, but the user should not assume that Ottawa is two times more relevant than Ontario. ```python PYTHON -[ - RerankResult, - RerankResult, - RerankResult +[ + RerankResult, + RerankResult, + RerankResult ] ``` diff --git a/fern/pages/v2/text-embeddings/reranking/overview.mdx b/fern/pages/v2/text-embeddings/reranking/overview.mdx index 1deca035..c97f0f94 100644 --- a/fern/pages/v2/text-embeddings/reranking/overview.mdx +++ b/fern/pages/v2/text-embeddings/reranking/overview.mdx @@ -4,7 +4,7 @@ slug: "v2/docs/overview" hidden: false -description: "This page describes how Cohere's ReRank models work." +description: "This page describes how Cohere's Rerank models work." image: "../../../../assets/images/f1cc130-cohere_meta_image.jpg" keywords: "Cohere, reranking models, large language models" @@ -19,7 +19,7 @@ The [Rerank API endpoint](/reference/rerank-1), powered by the [Rerank models](/ ### Example with Texts -In the example below, we use the [Rerank API endpoint](/reference/rerank-1) to index the list of `docs` from most to least relevant to the query ` What is the capital of the United States?`. +In the example below, we use the [Rerank API endpoint](/reference/rerank-1) to index the list of `documents` from most to least relevant to the query `"What is the capital of the United States?"`. **Request** @@ -27,91 +27,112 @@ In this example, the documents being passed in are a list of strings: ```python PYTHON import cohere -co = cohere.ClientV2(api_key="") +co = cohere.ClientV2() query = "What is the capital of the United States?" docs = [ - "Carson City is the capital city of the American state of Nevada. At the 2010 United States Census, Carson City had a population of 55,274.", - "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean that are a political division controlled by the United States. Its capital is Saipan.", - "Charlotte Amalie is the capital and largest city of the United States Virgin Islands. It has about 20,000 people. The city is on the island of Saint Thomas.", - "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. The President of the USA and many major national government offices are in the territory. This makes it the political center of the United States of America.", - "Capital punishment (the death penalty) has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states. The federal government (including the United States military) also uses capital punishment."] -results = co.rerank(model="rerank-english-v3.0", query=query, documents=docs, top_n=5, return_documents=True) + "Carson City is the capital city of the American state of Nevada. At the 2010 United States Census, Carson City had a population of 55,274.", + "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean that are a political division controlled by the United States. Its capital is Saipan.", + "Charlotte Amalie is the capital and largest city of the United States Virgin Islands. It has about 20,000 people. The city is on the island of Saint Thomas.", + "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. The President of the USA and many major national government offices are in the territory. This makes it the political center of the United States of America.", + "Capital punishment has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states. The federal government (including the United States military) also uses capital punishment." +] + +results = co.rerank( + model="rerank-v3.5", + query=query, + documents=docs, + top_n=5) ``` **Response** ```jsx { - "id": "97813271-fe74-465d-b9d5-577e77079253", - "results": [ - { - "document": { - "text": "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. The President of the USA and many major national government offices are in the territory. This makes it the political center of the United States of America." - }, - "index": 3, - "relevance_score": 0.9990564 - }, - { - "document": { - "text": "Capital punishment (the death penalty) has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states. The federal government (including the United States military) also uses capital punishment." - }, - "index": 4, - "relevance_score": 0.7516481 - }, - { - "document": { - "text": "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean that are a political division controlled by the United States. Its capital is Saipan." - }, - "index": 1, - "relevance_score": 0.08882029 - }, - { - "document": { - "text": "Carson City is the capital city of the American state of Nevada. At the 2010 United States Census, Carson City had a population of 55,274." - }, - "index": 0, - "relevance_score": 0.058238626 - }, - { - "document": { - "text": "Charlotte Amalie is the capital and largest city of the United States Virgin Islands. It has about 20,000 people. The city is on the island of Saint Thomas." - }, - "index": 2, - "relevance_score": 0.019946935 - } - ], - "meta": { - "api_version": { - "version": "2022-12-06" - }, - "billed_units": { - "search_units": 1 - } - } + "id": "97813271-fe74-465d-b9d5-577e77079253", + "results": [ + { + "index": 3, // "Washington, D.C. (also known as simply Washington or D.C., and officially as the District of Columbia) ..." + "relevance_score": 0.9990564 + }, + { + "index": 4, // "Capital punishment has existed in the United States since before the United States was a country. As of 2017 ..." + "relevance_score": 0.7516481 + }, + { + "index": 1, // "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean that are a political division ..." + "relevance_score": 0.08882029 + }, + { + "index": 0, // "Carson City is the capital city of the American state of Nevada. At the 2010 United States Census, Carson City had a ..." + "relevance_score": 0.058238626 + }, + { + "index": 2, // ""Charlotte Amalie is the capital and largest city of the United States Virgin Islands. It has about 20,000 people ..." + "relevance_score": 0.019946935 + } + ], + "meta": { + "api_version": { + "version": "2" + }, + "billed_units": { + "search_units": 1 + } + } } ``` -### Example with Semi-structured Data: +### Example with Structured Data: -Alternatively, you can pass in a JSON object and specify the fields you'd like to rank over. If you do not pass in any `rank_fields`, it will default to the text key. +If your documents contain structured data, for best performance we recommend formatting them as YAML strings. **Request** ```python PYTHON + +import yaml +import cohere + +co = cohere.ClientV2() + query = "What is the capital of the United States?" docs = [ - {"Title":"Facts about Carson City","Content":"Carson City is the capital city of the American state of Nevada. At the 2010 United States Census, Carson City had a population of 55,274."}, - {"Title":"The Commonwealth of Northern Mariana Islands","Content":"The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean that are a political division controlled by the United States. Its capital is Saipan."}, - {"Title":"The Capital of United States Virgin Islands","Content":"Charlotte Amalie is the capital and largest city of the United States Virgin Islands. It has about 20,000 people. The city is on the island of Saint Thomas."}, - {"Title":"Washington D.C.","Content":"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. The President of the USA and many major national government offices are in the territory. This makes it the political center of the United States of America."}, - {"Title":"Capital Punishment in the US","Content":"Capital punishment (the death penalty) has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states. The federal government (including the United States military) also uses capital punishment."}] -results = co.rerank(model="rerank-english-v3.0", query=query, documents=docs, rank_fields=['Title','Content'],top_n=5, return_documents=True) + { + "Title": "Facts about Carson City", + "Content": "Carson City is the capital city of the American state of Nevada. At the 2010 United States Census, Carson City had a population of 55,274." + }, + { + "Title": "The Commonwealth of Northern Mariana Islands", + "Content": "The Commonwealth of the Northern Mariana Islands is a group of islands in the Pacific Ocean that are a political division controlled by the United States. Its capital is Saipan." + }, + { + "Title": "The Capital of United States Virgin Islands", + "Content": "Charlotte Amalie is the capital and largest city of the United States Virgin Islands. It has about 20,000 people. The city is on the island of Saint Thomas." + }, + { + "Title": "Washington D.C.", + "Content":"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. The President of the USA and many major national government offices are in the territory. This makes it the political center of the United States of America." + }, + { + "Title": "Capital Punishment in the US", + "Content": "Capital punishment has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states. The federal government (including the United States military) also uses capital punishment." + } +] + +yaml_docs = [yaml.dump(doc, sort_keys=False) for doc in docs] + +results = co.rerank( + model="rerank-v3.5", + query=query, + documents=yaml_docs, + top_n=5 +) ``` -In the `docs` parameter, we are passing in a list of objects which have the key values: `[Title ,Content]`. As part of the Rerank call, we are specifying which keys to rank over, as well as the order in which the key value pairs should be considered. +In the `documents` parameter, we are passing in a list YAML strings, representing the structured data. ```python PYTHON { @@ -126,7 +147,7 @@ In the `docs` parameter, we are passing in a list of objects which have the key "relevance_score": 0.9987405 }, { - "document": { + "document": { "Content": "Capital punishment (the death penalty) has existed in the United States since before the United States was a country. As of 2017, capital punishment is legal in 30 of the 50 states. The federal government (including the United States military) also uses capital punishment.", "Title": "Capital Punishment in the US" }, @@ -172,7 +193,7 @@ In the `docs` parameter, we are passing in a list of objects which have the key ## Multilingual Reranking -Cohere offers a multilingual model, `rerank-multilingual-v3.0`. Please note that performance may vary across languages. The model is trained on the following languages: +Cohere's `rerank-v3.5` and `rerank-multilingual-v3.0` models have been trained for performance across a variety of languages. Please note that performance may vary across languages. The model is trained on the following languages: | ISO Code | Language Name | | -------- | -------------- | From e4f336221444b96b2b8018a528a76ef71e6af753 Mon Sep 17 00:00:00 2001 From: Trent Fowler Date: Sun, 1 Dec 2024 13:29:48 -0700 Subject: [PATCH 6/7] Another little change. --- .../text-embeddings/reranking/reranking-best-practices.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx b/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx index 61867716..80ba3cf8 100644 --- a/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx +++ b/fern/pages/text-embeddings/reranking/reranking-best-practices.mdx @@ -95,7 +95,7 @@ Looking at the example above, passing in `rank_fields=["Title","Content"]` would The most important output from the [Rerank API endpoint](/reference/rerank-1) is the absolute rank exposed in the response object. The score is query dependent, and could be higher or lower depending on the query and passages sent in. In the example below, what matters is that Ottawa is more relevant than Toronto, but the user should not assume that Ottawa is two times more relevant than Ontario. -```python PYTHON +``` [ RerankResult, RerankResult, From a0773ecdbe30db50db24f543eee0a748bc80ae27 Mon Sep 17 00:00:00 2001 From: Trent Fowler Date: Sun, 1 Dec 2024 13:34:11 -0700 Subject: [PATCH 7/7] Amending the models page for rerank availabilities on diff't platforms. --- fern/pages/models/models.mdx | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/fern/pages/models/models.mdx b/fern/pages/models/models.mdx index 45868f51..ed221cd1 100644 --- a/fern/pages/models/models.mdx +++ b/fern/pages/models/models.mdx @@ -106,7 +106,7 @@ The Rerank model can improve created models by re-organizing their results based | Latest Model | Description | Modality | Max Tokens | Endpoints | | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------|------------|-------------------| -| `rerank-english-v3.5` | A model for documents and semi-structured data (JSON). State-of-the-art performance in English and non-English languages; supports the same languages as embed-multilingual-v3.0. This model has a context length of 4096 tokens | Text | N/A | [Rerank](/reference/rerank) | +| `rerank-v3.5` | A model for documents and semi-structured data (JSON). State-of-the-art performance in English and non-English languages; supports the same languages as embed-multilingual-v3.0. This model has a context length of 4096 tokens | Text | N/A | [Rerank](/reference/rerank) | | `rerank-english-v3.0` | A model that allows for re-ranking English Language documents and semi-structured data (JSON). This model has a context length of 4096 tokens. | Text | N/A | [Rerank](/reference/rerank) | | `rerank-multilingual-v3.0` | A model for documents and semi-structure data (JSON) that are not in English. Supports the same languages as `embed-multilingual-v3.0`. This model has a context length of 4096 tokens. | Text | N/A | [Rerank](/reference/rerank) | | `rerank-english-v2.0` | A model that allows for re-ranking English language documents. This model has a context length of 512 tokens. | Text | N/A | [Rerank](/reference/rerank) | @@ -119,10 +119,9 @@ In this table, we provide some important context for using Cohere Rerank models | Model Name | Amazon Bedrock Model ID | Amazon SageMaker | Azure AI Studio Model ID | Oracle OCI Generative AI Service | | :------------------------- | :---------------------- | :-------------------- | :----------------------- | :------------------------------- | -| `rerank-english-v3.0` | Not yet available | Unique per deployment | Not yet available | N/A | -| `rerank-multilingual-v3.0` | Not yet available | Unique per deployment | Not yet available | N/A | -| `rerank-english-v2.0` | N/A | N/A | N/A | N/A | -| `rerank-multilingual-v2.0` | N/A | N/A | N/A | N/A | +| `rerank-v3.5` | Not yet available | Unique per deployment | Coming soon | N/A | +| `rerank-english-v3.0` | Not available | Unique per deployment | Not yet available | N/A | +| `rerank-multilingual-v3.0` | Not available | Unique per deployment | Not yet available | N/A |