# Cohere > Cohere's API documentation helps developers easily integrate natural language processing and generation into their products. ## Pages - [Cohere Documentation](cohere-documentation.md): Cohere's API documentation helps developers easily integrate natural language processing and generation into their pr... - [An Overview of The Cohere Platform](an-overview-of-the-cohere-platform.md): Cohere offers world-class Large Language Models (LLMs) like Command, Rerank, and Embed. These help developers and ent... - [Installation](installation.md): A guide for installing the Cohere SDK, supported in 4 different languages – Python, TypeScript, Java, and Go. - [Creating a client](creating-a-client.md): A guide for creating Cohere API client using Cohere SDK, supported in 4 different languages – Python, TypeScript, Jav... - [Text generation - quickstart](text-generation-quickstart.md): A quickstart guide for performing text generation with Cohere's Command models (v2 API). - [Retrieval augmented generation (RAG) - quickstart](retrieval-augmented-generation-rag-quickstart.md): A quickstart guide for performing retrieval augmented generation (RAG) with Cohere's Command models (v2 API). - [Tool use & agents - quickstart](tool-use-agents-quickstart.md): A quickstart guide for using tool use and building agents with Cohere's Command models (v2 API). - [Semantic search - quickstart](semantic-search-quickstart.md): A quickstart guide for performing text semantic search with Cohere's Embed models (v2 API). - [Reranking - quickstart](reranking-quickstart.md): A quickstart guide for performing reranking with Cohere's Reranking models (v2 API). - [An Overview of the Developer Playground](an-overview-of-the-developer-playground.md): The Cohere Playground is a powerful visual interface for testing Cohere's generation and embedding language models wi... - [Frequently Asked Questions About Cohere](frequently-asked-questions-about-cohere.md): Cohere is a powerful platform for using Large Language Models (LLMs). This page covers FAQs related to functionality,... - [An Overview of Cohere's Models](an-overview-of-coheres-models.md): Cohere has a variety of models that cover many different use cases. If you need more customization, you can train a m... - [Command A](command-a.md): Command A is a performant mode good at tool use, RAG, agents, and multilingual use cases. It has 111 billion paramete... - [Cohere's Command A Reasoning Model](coheres-command-a-reasoning-model.md): Command A Reasoning excels in tool use, agentic workflows, and complex problem-solving. It has 111 billion parameters... - [Cohere's Command A Translate Model](coheres-command-a-translate-model.md): Command A Translate is a state of the art model performant in 23 languages. It has a context length of 16K tokens and... - [Cohere's Command A Vision Model](coheres-command-a-vision-model.md): Command A Vision is a powerful visual language model capable of interacting with image inputs. This document contains... - [Cohere's Command R7B Model](coheres-command-r7b-model.md): Command R7B is the smallest, fastest, and final model in our R family of enterprise-focused large language models. It... - [Cohere's Command R+ Model](coheres-command-r-model.md): Command R+ is Cohere's optimized for conversational interaction and long-context tasks, best suited for complex RAG w... - [Cohere's Command R Model](coheres-command-r-model-2.md): Command R is a conversational model that excels in language tasks and supports multiple languages, making it ideal fo... - [Cohere's Embed Models (Details and Application)](coheres-embed-models-details-and-application.md): Explore Embed models for text classification and embedding generation in English and multiple languages, with details... - [Cohere's Rerank Model (Details and Application)](coheres-rerank-model-details-and-application.md): This page describes how Cohere's Rerank models work and how to use them. - [Aya Family of Models](aya-family-of-models.md): Understand Cohere Labs groundbreaking multilingual Aya models, which aim to bring many more languages into generative... - [Aya Vision](aya-vision.md): Understand Cohere Labs groundbreaking multilingual model Aya Vision, a state-of-the-art multimodal language model exc... - [Aya Expanse](aya-expanse.md): Understand Cohere Labs highly performant multilingual Aya models, which aim to bring many more languages into generat... - [Introduction to Text Generation at Cohere](introduction-to-text-generation-at-cohere.md): This page describes how a large language model generates textual output. - [Using the Cohere Chat API for Text Generation](using-the-cohere-chat-api-for-text-generation.md): How to use the Chat API endpoint with Cohere LLMs to generate text responses in a conversational interface - [Reasoning Capabilities](reasoning-capabilities.md): Reasoning models excel at tool use, agentic workflows, and complex problem-solving. This page provides a general over... - [Using Cohere's Models to Work with Image Inputs](using-coheres-models-to-work-with-image-inputs.md): This page describes how a Cohere large language model works with image inputs. It covers passing images with the API,... - [A Guide to Streaming Responses](a-guide-to-streaming-responses.md): The document explains how the Chat API can stream events like text generation in real-time. - [Sample output (streamed)](sample-output-streamed.md): A large language model (LLM) is a type of artificial neural network model that has been trained on massive amounts of... - [Sample events](sample-events.md): type='content-delta' index=0 delta=ChatContentDeltaEventDelta(message=ChatContentDeltaEventDeltaMessage(content=ChatC... - [Sample event](sample-event.md): type='citation-start' index=0 delta=CitationStartEventDelta(message=CitationStartEventDeltaMessage(citations=Citation... - [Sample events](sample-events-2.md): type='tool-plan-delta' delta=ChatToolPlanDeltaEventDelta(tool_plan=None, message={'tool_plan': 'I'}) - [Sample event](sample-event-2.md): type='tool-call-start' index=0 delta=ChatToolCallStartEventDelta(tool_call=None, message={'tool_calls': {'id': 'get_w... - [Sample events](sample-events-3.md): type='tool-call-delta' index=0 delta=ChatToolCallDeltaEventDelta(tool_call=None, message={'tool_calls': {'function': ... - [How do Structured Outputs Work?](how-do-structured-outputs-work.md): This page describes how to get Cohere models to create outputs in a certain format, such as JSON, TOOLS, using parame... - [Example response](example-response.md): { - [Example response](example-response-2.md): { - [Parameter Types in Structured Outputs (JSON)](parameter-types-in-structured-outputs-json.md): This page shows usage examples of the JSON Schema parameter types supported in Structured Outputs (JSON). - [How to Get Predictable Outputs with Cohere Models](how-to-get-predictable-outputs-with-cohere-models.md): Strategies for decoding text, and the parameters that impact the randomness and predictability of a language model's ... - [Advanced Generation Parameters](advanced-generation-parameters.md): This page describes advanced parameters for controlling generation. - [Retrieval Augmented Generation (RAG)](retrieval-augmented-generation-rag.md): Guide on using Cohere's Retrieval Augmented Generation (RAG) capabilities such as document grounding and citations. - [Retrieve the documents](retrieve-the-documents.md): documents = [ - [Add the user message](add-the-user-message.md): message = "Where do the tallest penguins live?" - [response.message.content[0].text](responsemessagecontent0text.md): Emperor penguins are the tallest penguins. They only live in Antarctica. - [response.message.citations](responsemessagecitations.md): [Citation(start=0, - [Define the query generation tool](define-the-query-generation-tool.md): query_gen_tool = [ - [Define a system message to optimize search query generation](define-a-system-message-to-optimize-search-query-generation.md): instructions = "Write a search query that will find helpful information for answering the user's question accurately.... - [Generate search queries (if any)](generate-search-queries-if-any.md): import json - [Sample response](sample-response.md): ['popularity of NSync', 'popularity of Backstreet Boys'] - [Add the user message](add-the-user-message-2.md): message = "Who is more popular: Nsync or Backstreet Boys?" - [(truncated for brevity)](truncated-for-brevity.md): [Citation(start=36, - [End-to-end example of RAG with Chat, Embed, and Rerank](end-to-end-example-of-rag-with-chat-embed-and-rerank.md): Guide on using Cohere's Retrieval Augmented Generation (RAG) capabilities covering the Chat, Embed, and Rerank endpoi... - [Compute dot product similarity and display results](compute-dot-product-similarity-and-display-results.md): n = 5 - [RAG Streaming](rag-streaming.md): Guide on implementing streaming for RAG with Cohere and details on the events stream (API v2). - [RAG Citations](rag-citations.md): Guide on accessing and utilizing citations generated by the Cohere Chat endpoint for RAG. It covers both non-streamin... - [! pip install -U cohere](pip-install-u-cohere.md): import cohere - [An Overview of Tool Use with Cohere](an-overview-of-tool-use-with-cohere.md): Learn when to use leverage multi-step tool use in your workflows. - [Basic usage of tool use (function calling)](basic-usage-of-tool-use-function-calling.md): An overview of using Cohere's tool use capabilities, enabling developers to build agentic workflows (API v2). - [Example: List of objects](example-list-of-objects.md): weather_search_results = [ - [Usage patterns for tool use (function calling)](usage-patterns-for-tool-use-function-calling.md): Guide on implementing various tool use patterns with the Cohere Chat endpoint such as parallel tool calling, multi-st... - [Step 1: Get the user message](step-1-get-the-user-message.md): messages = [ - [Step 2: Generate tool calls (if any)](step-2-generate-tool-calls-if-any.md): model = "command-a-03-2025" - [Print final response](print-final-response.md): print("RESPONSE:") - [Print citations (if any)](print-citations-if-any.md): verbose_source = ( - [Parameter types for tool use (function calling)](parameter-types-for-tool-use-function-calling.md): Guide on using structured outputs with tool parameters in the Cohere Chat API. Includes guide on supported parameter ... - [Streaming for tool use (function calling)](streaming-for-tool-use-function-calling.md): Guide on implementing streaming for tool use in Cohere's platform and details on the events stream (API v2). - [User message](user-message.md): "What's the weather in Madrid and Brasilia?" - [Events stream](events-stream.md): type='message-start' id='fba98ad3-e5a1-413c-a8de-84fbf9baabf7' delta=ChatMessageStartEventDelta(message=ChatMessageSt... - [Citations for tool use (function calling)](citations-for-tool-use-function-calling.md): Guide on accessing and utilizing citations generated by the Cohere Chat endpoint for tool use. It covers both non-str... - [! pip install -U cohere](pip-install-u-cohere-2.md): import cohere - [A Guide to Tokens and Tokenizers](a-guide-to-tokens-and-tokenizers.md): This document describes how to use the tokenize and detokenize API endpoints. - [pip install tokenizers](pip-install-tokenizers.md): from tokenizers import Tokenizer - [download the tokenizer](download-the-tokenizer.md): tokenizer_url = ( - [Summarizing Text with the Chat Endpoint](summarizing-text-with-the-chat-endpoint.md): Learn how to perform text summarization using Cohere's Chat endpoint with features like length control and RAG. - [Before](before.md): co.summarize( - [After](after.md): message = """Write a short summary from the following text in bullet point format, in different words. - [Safety Modes](safety-modes.md): The safety modes documentation describes how to use default and strict modes in order to exercise additional control ... - [Introduction to Embeddings at Cohere](introduction-to-embeddings-at-cohere.md): Embeddings transform text into numerical data, enabling language-agnostic similarity searches and efficient storage w... - [get the embeddings](get-the-embeddings.md): phrases = ["i love soup", "soup is my favorite", "london is far away"] - [compare them](compare-them.md): def calculate_similarity(a, b): - [The model accepts input in base64 as a Data URL](the-model-accepts-input-in-base64-as-a-data-url.md): def image_to_base64_data_url(image_path): - [The model accepts input in base64 as a Data URL](the-model-accepts-input-in-base64-as-a-data-url-2.md): def image_to_base64_data_url(image_path): - [Embed an Images and Texts separately](embed-an-images-and-texts-separately.md): with open("./content/finn.jpeg", "rb") as image_file: - [Step 3: Format as data URL](step-3-format-as-data-url.md): data_url = f"data:image/jpeg;base64,{encoded_string}" - [This will return a list of length 1 with the texts and image in a combined embedding](this-will-return-a-list-of-length-1-with-the-texts-and-image-in-a-combined-embed.md): res - [print out the embeddings](print-out-the-embeddings.md): response.float # returns a vector that is 1024 dimensions - [Semantic Search with Embeddings](semantic-search-with-embeddings.md): Examples on how to use the Embed endpoint to perform semantic search (API v2). - [Constructing the embed_input object](constructing-the-embed-input-object.md): embed_input = [ - [Embed the documents](embed-the-documents.md): doc_emb = co.embed( - [Add the user query](add-the-user-query.md): query = "COVID-19 Symptoms" - [Embed the query](embed-the-query.md): query_emb = co.embed( - [Calculate similarity scores](calculate-similarity-scores.md): scores = np.dot(query_emb, np.transpose(doc_emb))[0] - [Sort and filter documents based on scores](sort-and-filter-documents-based-on-scores.md): top_n = 5 - [Display search results](display-search-results.md): for idx, docs_idx in enumerate(top_doc_idxs): - [Constructing the embed_input object](constructing-the-embed-input-object-2.md): embed_input = [ - [Embed the documents](embed-the-documents-2.md): doc_emb = co.embed( - [Add the user query](add-the-user-query-2.md): query = "What's your remote-working policy?" - [Embed the query](embed-the-query-2.md): query_emb = co.embed( - [Calculate similarity scores](calculate-similarity-scores-2.md): scores = np.dot(query_emb, np.transpose(doc_emb))[0] - [Sort and filter documents based on scores](sort-and-filter-documents-based-on-scores-2.md): top_n = 4 - [Display search results](display-search-results-2.md): for idx, docs_idx in enumerate(top_doc_idxs): - [Generate the document embeddings](generate-the-document-embeddings.md): embeddings = [] - [Store the embeddings in a vector database](store-the-embeddings-in-a-vector-database.md): ids = [] - [Generate the query embedding](generate-the-query-embedding.md): query_embeddings = co.embed( - [Search the vector database](search-the-vector-database.md): results = collection.query( - [Print the id of the top-ranked page](print-the-id-of-the-top-ranked-page.md): print(results["ids"][0][0]) - [Unlocking the Power of Multimodal Embeddings](unlocking-the-power-of-multimodal-embeddings.md): Multimodal embeddings convert text and images into embeddings for search and classification (API v2). - [Import the necessary packages](import-the-necessary-packages.md): import os - [Defining the function to convert an image to a base 64 Data URL](defining-the-function-to-convert-an-image-to-a-base-64-data-url.md): def image_to_base64_data_url(image_path): - [Batch Embedding Jobs with the Embed API](batch-embedding-jobs-with-the-embed-api.md): Learn how to use the Embed Jobs API to handle large text data efficiently with a focus on creating datasets and runni... - [An Overview of Cohere's Rerank Model](an-overview-of-coheres-rerank-model.md): This page describes how Cohere's Rerank models work. - [Best Practices for using Rerank](best-practices-for-using-rerank.md): Tips for optimal endpoint performance, including constraints on the number of documents, tokens per document, and tok... - [Different Types of API Keys and Rate Limits](different-types-of-api-keys-and-rate-limits.md): This page describes Cohere API rate limits for production and evaluation keys. - [Going Live with a Cohere Model](going-live-with-a-cohere-model.md): Learn to upgrade from a Trial to a Production key; understand the limitations and benefits of each and go live with C... - [Deprecations](deprecations.md): Learn about Cohere's deprecation policies and recommended replacements - [Best Practices:](best-practices.md): 1. Regularly check our documentation for updates on announcements regarding the status of models. - [How Does Cohere's Pricing Work?](how-does-coheres-pricing-work.md): This page details Cohere's pricing model. Our models can be accessed directly through our API, allowing for the creat... - [Integrating Embedding Models with Other Tools](integrating-embedding-models-with-other-tools.md): Learn how to integrate Cohere embeddings with open-source vector search engines for enhanced applications. - [Elasticsearch and Cohere (Integration Guide)](elasticsearch-and-cohere-integration-guide.md): Learn how to create a semantic search pipeline with Elasticsearch and Cohere's generative AI capabilities. - [Confirm the client has connected](confirm-the-client-has-connected.md): print(client.info()) - [Build a Hybrid Search Index with Cohere and Elasticsearch](build-a-hybrid-search-index-with-cohere-and-elasticsearch.md): One of the biggest pain points of building a vector search index is computing embeddings for a large corpus of data. ... - [Delete the inference model if it already exists](delete-the-inference-model-if-it-already-exists.md): client.options(ignore_status=[404]).inference.delete( - [Load the response data into a JSON object](load-the-response-data-into-a-json-object.md): jsonl_data = response.content.decode("utf-8").splitlines() - [Prepare the documents to be indexed](prepare-the-documents-to-be-indexed.md): documents = [] - [Use the bulk endpoint to index](use-the-bulk-endpoint-to-index.md): helpers.bulk(client, documents) - [Display the first 10 results](display-the-first-10-results.md): for document in raw_documents[0:10]: - [Format the documents for ranking](format-the-documents-for-ranking.md): documents = [] - [Display the first 10 results](display-the-first-10-results-2.md): for document in raw_documents[0:10]: - [Format the documents for ranking](format-the-documents-for-ranking-2.md): documents = [] - [Delete the inference model if it already exists](delete-the-inference-model-if-it-already-exists-2.md): client.options(ignore_status=[404]).inference.delete(inference_id="cohere_rerank") - [Reconstruct the input documents based on the index provided in the rereank response](reconstruct-the-input-documents-based-on-the-index-provided-in-the-rereank-respo.md): ranked_documents = [] - [Print the top 10 results](print-the-top-10-results.md): for document in ranked_documents[0:10]: - [MongoDB and Cohere (Integration Guide)](mongodb-and-cohere-integration-guide.md): Build semantic search and RAG systems using Cohere and MongoDB Atlas Vector Search. - [Redis and Cohere (Integration Guide)](redis-and-cohere-integration-guide.md): Learn how to integrate Cohere with Redis for similarity searches on text data with this step-by-step guide. - [Building a Retrieval Pipeline with Cohere and Redis](building-a-retrieval-pipeline-with-cohere-and-redis.md): To configure a Redis index you can either specify a`yaml`file or import a dictionary. In this tutorial we will be u... - [create a vectorizer](create-a-vectorizer.md): api_key = "{Insert your cohere API Key}" - [construct a search index from the schema - this schema is called "semantic_search_demo"](construct-a-search-index-from-the-schema-this-schema-is-called-semantic-search-d.md): schema = IndexSchema.from_yaml("./schema.yaml") - [create the index (no data yet)](create-the-index-no-data-yet.md): index.create(overwrite=True) - [read in your documents](read-in-your-documents.md): jsonl_file_path = "data/redis_guide_data.jsonl" - [hash data structures get serialized as a string and thus we store the embeddings in hashes as a byte string (handled by numpy)](hash-data-structures-get-serialized-as-a-string-and-thus-we-store-the-embeddings.md): res = cohere_vectorizer.embed_many( - [contruct the data payload to be uploaded to your index](contruct-the-data-payload-to-be-uploaded-to-your-index.md): data = [ - [load the data into your index](load-the-data-into-your-index.md): index.load(data) - [use the Cohere vectorizer again to create a query embedding](use-the-cohere-vectorizer-again-to-create-a-query-embedding.md): query_embedding = cohere_vectorizer.embed( - [Redis Filters](redis-filters.md) - [Initialize a tag filter](initialize-a-tag-filter.md): tag_filter = Tag("title") == "Microsoft Office" - [set the tag filter on our existing query](set-the-tag-filter-on-our-existing-query.md): query.set_filter(tag_filter) - [define a tag match on the title, text match on the text field, and numeric filter on the views field](define-a-tag-match-on-the-title-text-match-on-the-text-field-and-numeric-filter-.md): filter_data = ( - [reinitialize the query with the filter expression](reinitialize-the-query-with-the-filter-expression.md): query = VectorQuery( - [Haystack and Cohere (Integration Guide)](haystack-and-cohere-integration-guide.md): Build custom LLM applications with Haystack, now integrated with Cohere for embedding, generation, chat, and retrieval. - [{'llm': {'replies': [ChatMessage(content='The Cohere platform builds natural language processing and generation into your product with a few lines of code... \nIs', role=, name=None, meta={'model': 'command', 'usage': {'prompt_tokens': 273, 'response_tokens': 165, 'total_tokens': 438, 'billed_tokens': 430}, 'index': 0, 'finish_reason': None, 'documents': None, 'citations': None})]}}](llm-replies-chatmessagecontentthe-cohere-platform-builds-natural-language-proces.md): RAG provides an LLM with context allowing it to generate better answers. You can use any of [Cohere’s models](/docs/m... - [{'llm': {'replies': [' Paris is the capital of France. It is known for its history, culture, and many iconic landmarks, such as the Eiffel Tower and Notre-Dame Cathedral. '], 'meta': [{'finish_reason': 'COMPLETE'}]}}](llm-replies-paris-is-the-capital-of-france-it-is-known-for-its-history-culture-a.md): You can use Cohere’s embedding models within your Haystack RAG pipelines. The list of all supported models can be fou... - [[Document(id=..., content: 'My name is Wolfgang and I live in Berlin', embedding: vector of size 4096), Document(id=..., content: 'Germany has many big cities', embedding: vector of size 4096)]](documentid-content-my-name-is-wolfgang-and-i-live-in-berlin-embedding-vector-of-.md): After the indexing pipeline has added the embeddings to the document store, you can build a retrieval pipeline that g... - [Document(id=..., text: 'My name is Wolfgang and I live in Berlin')](documentid-text-my-name-is-wolfgang-and-i-live-in-berlin.md) - [Pinecone and Cohere (Integration Guide)](pinecone-and-cohere-integration-guide.md): This page describes how to integrate Cohere with the Pinecone vector database. - [Weaviate and Cohere (Integration Guide)](weaviate-and-cohere-integration-guide.md): This page describes how to integrate Cohere with the Weaviate database. - [Import the weaviate modules to interact with the Weaviate vector database](import-the-weaviate-modules-to-interact-with-the-weaviate-vector-database.md): import weaviate - [Define headers for the API requests, including the Cohere API key](define-headers-for-the-api-requests-including-the-cohere-api-key.md): headers = { - [Connect to the Weaviate cloud instance](connect-to-the-weaviate-cloud-instance.md): client = weaviate.connect_to_weaviate_cloud( - [This is where the "Healthcare_Compliance" collection is created in Weaviate.](this-is-where-the-healthcare-compliance-collection-is-created-in-weaviate.md): client.collections.create( - [Define the list of healthcare compliance documents](define-the-list-of-healthcare-compliance-documents.md): hl_compliance_docs = [ - [Retrieve the "Healthcare_Compliance" collection from the Weaviate client](retrieve-the-healthcare-compliance-collection-from-the-weaviate-client.md): collection = client.collections.get("Healthcare_Compliance") - [Use a dynamic batch process to add multiple documents to the collection efficiently](use-a-dynamic-batch-process-to-add-multiple-documents-to-the-collection-efficien.md): with collection.batch.dynamic() as batch: - [Import the MetadataQuery class from weaviate.classes.query to handle metadata in queries](import-the-metadataquery-class-from-weaviateclassesquery-to-handle-metadata-in-q.md): from weaviate.classes.query import MetadataQuery - [Retrieve the "Healthcare_Compliance" collection from the Weaviate client](retrieve-the-healthcare-compliance-collection-from-the-weaviate-client-2.md): collection = client.collections.get("Healthcare_Compliance") - [Perform a near_text search for documents related to "policies related to drug compounding"](perform-a-near-text-search-for-documents-related-to-policies-related-to-drug-com.md): response = collection.query.near_text( - [Iterate over the retrieved objects and print their details](iterate-over-the-retrieved-objects-and-print-their-details.md): for obj in response.objects: - [Import the weaviate module to interact with the Weaviate vector database](import-the-weaviate-module-to-interact-with-the-weaviate-vector-database.md): import weaviate - [Define headers for the API requests, including the Cohere API key](define-headers-for-the-api-requests-including-the-cohere-api-key-2.md): headers = { - [Connect to the Weaviate cloud instance](connect-to-the-weaviate-cloud-instance-2.md): client = weaviate.connect_to_weaviate_cloud( - [Create a new collection named "Legal_Docs" in the Weaviate database](create-a-new-collection-named-legal-docs-in-the-weaviate-database.md): client.collections.create( - [Retrieve the "Legal_Docs" collection from the Weaviate client](retrieve-the-legal-docs-collection-from-the-weaviate-client.md): collection = client.collections.get("Legal_Docs") - [Use a dynamic batch process to add multiple documents to the collection efficiently](use-a-dynamic-batch-process-to-add-multiple-documents-to-the-collection-efficien-2.md): with collection.batch.dynamic() as batch: - [Import the MetadataQuery class from weaviate.classes.query to handle metadata in queries](import-the-metadataquery-class-from-weaviateclassesquery-to-handle-metadata-in-q-2.md): from weaviate.classes.query import MetadataQuery - [Retrieve the "Legal_Docs" collection from the Weaviate client](retrieve-the-legal-docs-collection-from-the-weaviate-client-2.md): collection = client.collections.get("Legal_Docs") - [Perform a near_text semantic search for documents](perform-a-near-text-semantic-search-for-documents.md): response = collection.query.near_text( - [Iterate over the retrieved objects and print their details](iterate-over-the-retrieved-objects-and-print-their-details-2.md): for obj in response.objects: - [Import the Rerank class from weaviate.classes.query to enable reranking in queries](import-the-rerank-class-from-weaviateclassesquery-to-enable-reranking-in-queries.md): from weaviate.classes.query import Rerank - [Perform a near_text search with reranking for documents related to "property contracts and zoning regulations"](perform-a-near-text-search-with-reranking-for-documents-related-to-property-cont.md): rerank_response = collection.query.near_text( - [Display the reranked search results](display-the-reranked-search-results.md): print("Reranked Search Results:") - [Create a new collection named "Legal_Docs" in the Weaviate database](create-a-new-collection-named-legal-docs-in-the-weaviate-database-2.md): client.collections.create( - [Retrieve the "Legal_Docs_RAG" collection from the Weaviate client](retrieve-the-legal-docs-rag-collection-from-the-weaviate-client.md): collection = client.collections.get("Legal_Docs_RAG") - [Use a dynamic batch process to add multiple documents to the collection efficiently](use-a-dynamic-batch-process-to-add-multiple-documents-to-the-collection-efficien-3.md): with collection.batch.dynamic() as batch: - [To generate text for each object in the search results, use the single prompt method.](to-generate-text-for-each-object-in-the-search-results-use-the-single-prompt-met.md) - [The example below generates outputs for each of the n search results, where n is specified by the limit parameter.](the-example-below-generates-outputs-for-each-of-the-n-search-results-where-n-is-.md): collection = client.collections.get("Legal_Docs_RAG") - [Open Search and Cohere (Integration Guide)](open-search-and-cohere-integration-guide.md): Unlock the power of search and analytics with OpenSearch, enhanced by ML connectors like Cohere and Amazon Bedrock. - [Vespa and Cohere (Integration Guide)](vespa-and-cohere-integration-guide.md): This page describes how to integrate Cohere with the Vespa database. - [Qdrant and Cohere (Integration Guide)](qdrant-and-cohere-integration-guide.md): This page describes how to integrate Cohere with the Qdrant vector database. - [Milvus and Cohere (Integration Guide)](milvus-and-cohere-integration-guide.md): This page describes integrating Cohere with the Milvus vector database. - [Zilliz and Cohere (Integration Guide)](zilliz-and-cohere-integration-guide.md): This page describes how to integrate Cohere with the Zilliz database. - [Chroma and Cohere (Integration Guide)](chroma-and-cohere-integration-guide.md): This page describes how to integrate Cohere and Chroma. - [Cohere and LangChain (Integration Guide)](cohere-and-langchain-integration-guide.md): Integrate Cohere with LangChain for advanced chat features, RAG, embeddings, and reranking; this guide includes code ... - [Cohere Chat on LangChain (Integration Guide)](cohere-chat-on-langchain-integration-guide.md): Integrate Cohere with LangChain to build applications using Cohere's models and LangChain tools. - [Define the Cohere LLM](define-the-cohere-llm.md): llm = ChatCohere( - [Send a chat message without chat history](send-a-chat-message-without-chat-history.md): current_message = [HumanMessage(content="knock knock")] - [Send a chat message with chat history, note the last message is the current user message](send-a-chat-message-with-chat-history-note-the-last-message-is-the-current-user-.md): current_message_and_history = [ - [Internet search tool - you can use any tool, and there are lots of community tools in LangChain.](internet-search-tool-you-can-use-any-tool-and-there-are-lots-of-community-tools-.md) - [To use the Tavily tool you will need to set an API key in the TAVILY_API_KEY environment variable.](to-use-the-tavily-tool-you-will-need-to-set-an-api-key-in-the-tavily-api-key-env.md): os.environ["TAVILY_API_KEY"] = "TAVILY_API_KEY" - [Define the Cohere LLM](define-the-cohere-llm-2.md): llm = ChatCohere( - [Create an agent](create-an-agent.md): agent = create_cohere_react_agent( - [Create an agent executor](create-an-agent-executor.md): agent_executor = AgentExecutor( - [Generate a response](generate-a-response.md): response = agent_executor.invoke( - [See Cohere's response](see-coheres-response.md): print(response.get("output")) - [Cohere provides exact citations for the sources it used](cohere-provides-exact-citations-for-the-sources-it-used.md): print(response.get("citations")) - [User query we will use for the generation](user-query-we-will-use-for-the-generation.md): user_query = "What is cohere?" - [Define the Cohere LLM](define-the-cohere-llm-3.md): llm = ChatCohere( - [Create the Cohere rag retriever using the chat model](create-the-cohere-rag-retriever-using-the-chat-model.md): rag = CohereRagRetriever(llm=llm, connectors=[]) - [Create the wikipedia retriever](create-the-wikipedia-retriever.md): wiki_retriever = WikipediaRetriever() - [Get the relevant documents from wikipedia](get-the-relevant-documents-from-wikipedia.md): wiki_docs = wiki_retriever.invoke(user_query) - [Get the cohere generation from the cohere rag retriever](get-the-cohere-generation-from-the-cohere-rag-retriever.md): docs = rag.invoke(user_query, documents=wiki_docs) - [Print the documents](print-the-documents.md): print("Documents:") - [Print the final generation](print-the-final-generation.md): answer = docs[-1].page_content - [Print the final citations](print-the-final-citations.md): citations = docs[-1].metadata["citations"] - [Define the Cohere LLM](define-the-cohere-llm-4.md): llm = ChatCohere( - [Create the Cohere rag retriever using the chat model](create-the-cohere-rag-retriever-using-the-chat-model-2.md): rag = CohereRagRetriever(llm=llm, connectors=[]) - [Print the documents](print-the-documents-2.md): print("Documents:") - [Print the final generation](print-the-final-generation-2.md): answer = docs[-1].page_content - [Print the final citations](print-the-final-citations-2.md): citations = docs[-1].metadata["citations"] - [Define the Cohere LLM](define-the-cohere-llm-5.md): llm = ChatCohere( - [Create the Cohere rag retriever using the chat model with the web search connector](create-the-cohere-rag-retriever-using-the-chat-model-with-the-web-search-connect.md): rag = CohereRagRetriever(llm=llm, connectors=[{"id": "web-search"}]) - [Print the documents](print-the-documents-3.md): print("Documents:") - [Print the final generation](print-the-final-generation-3.md): answer = docs[-1].page_content - [Print the final citations](print-the-final-citations-3.md): citations = docs[-1].metadata["citations"] - [Define the Cohere LLM](define-the-cohere-llm-6.md): llm = ChatCohere( - [Define the Cohere LLM](define-the-cohere-llm-7.md): llm = ChatCohere( - [Define the Cohere LLM](define-the-cohere-llm-8.md): llm = ChatCohere( - [Cohere Embed on LangChain (Integration Guide)](cohere-embed-on-langchain-integration-guide.md): This page describes how to work with Cohere's embeddings models and LangChain. - [Define the Cohere embedding model](define-the-cohere-embedding-model.md): embeddings = CohereEmbeddings( - [Embed a document](embed-a-document.md): text = "This is a test document." - [Load text files and split into chunks, you can also use data gathered elsewhere in your application](load-text-files-and-split-into-chunks-you-can-also-use-data-gathered-elsewhere-i.md): raw_documents = WebBaseLoader( - [Create a vector store from the documents](create-a-vector-store-from-the-documents.md): db = Chroma.from_documents(documents, embeddings) - [Create the cohere rag retriever using the chat model](create-the-cohere-rag-retriever-using-the-chat-model-3.md): rag = CohereRagRetriever(llm=llm) - [Print the documents](print-the-documents-4.md): print("Documents:") - [Print the final generation](print-the-final-generation-4.md): answer = docs[-1].page_content - [Print the final citations](print-the-final-citations-4.md): citations = docs[-1].metadata["citations"] - [Replace the profile name with the one created in the setup.](replace-the-profile-name-with-the-one-created-in-the-setup.md): embeddings = BedrockEmbeddings( - [Cohere Rerank on LangChain (Integration Guide)](cohere-rerank-on-langchain-integration-guide.md): This page describes how to integrate Cohere's ReRank models with LangChain. - [Define the Cohere LLM](define-the-cohere-llm-9.md): llm = ChatCohere( - [Define the Cohere embedding model](define-the-cohere-embedding-model-2.md): embeddings = CohereEmbeddings( - [Load text files and split into chunks, you can also use data gathered elsewhere in your application](load-text-files-and-split-into-chunks-you-can-also-use-data-gathered-elsewhere-i-2.md): raw_documents = WebBaseLoader( - [Create a vector store from the documents](create-a-vector-store-from-the-documents-2.md): db = Chroma.from_documents(documents, embeddings) - [Create Cohere's reranker with the vector DB using Cohere's embeddings as the base retriever](create-coheres-reranker-with-the-vector-db-using-coheres-embeddings-as-the-base-.md): reranker = CohereRerank( - [Print the relevant documents from using the embeddings and reranker](print-the-relevant-documents-from-using-the-embeddings-and-reranker.md): print(compressed_docs) - [Create the cohere rag retriever using the chat model](create-the-cohere-rag-retriever-using-the-chat-model-4.md): rag = CohereRagRetriever(llm=llm, connectors=[]) - [Print the documents](print-the-documents-5.md): print("Documents:") - [Print the final generation](print-the-final-generation-5.md): answer = docs[-1].page_content - [Print the final citations](print-the-final-citations-5.md): citations = docs[-1].metadata["citations"] - [Cohere Tools on LangChain (Integration Guide)](cohere-tools-on-langchain-integration-guide.md): Explore code examples for multi-step and single-step tool usage in chatbots, harnessing internet search and vector st... - [Define the Cohere LLM](define-the-cohere-llm-10.md): llm = ChatCohere( - [Preamble](preamble.md): preamble = """ - [Prompt template](prompt-template.md): prompt = ChatPromptTemplate.from_template("{input}") - [Create the ReAct agent](create-the-react-agent.md): agent = create_cohere_react_agent( - [Data model](data-model.md): class web_search(BaseModel): - [Preamble](preamble-2.md): preamble = """You are an expert at routing a user question to a vectorstore or web search. - [Define the Cohere LLM](define-the-cohere-llm-11.md): llm = ChatCohere( - [Download the Chinook SQLite database](download-the-chinook-sqlite-database.md): url = " - [Define the Cohere LLM](define-the-cohere-llm-12.md): llm = ChatCohere( - [Define the Cohere LLM](define-the-cohere-llm-13.md): llm = ChatCohere( - [Define the Cohere LLM](define-the-cohere-llm-14.md): llm = ChatCohere( - [Create a state graph](create-a-state-graph.md): class State(TypedDict): - [Define the Cohere LLM](define-the-cohere-llm-15.md): llm = ChatCohere( - [Add nodes](add-nodes.md): def chatbot(state: State): - [Compile the graph](compile-the-graph.md): graph = graph_builder.compile() - [Run the chatbot](run-the-chatbot.md): while True: - [Create a tool](create-a-tool.md): tool = TavilySearchResults(max_results=2) - [Create a state graph](create-a-state-graph-2.md): class State(TypedDict): - [Define the LLM](define-the-llm.md): llm = ChatCohere( - [Bind the tools to the LLM](bind-the-tools-to-the-llm.md): llm_with_tools = llm.bind_tools(tools) - [Add nodes](add-nodes-2.md): def chatbot(state: State): - [Compile the graph](compile-the-graph-2.md): graph = graph_builder.compile() - [Run the chatbot](run-the-chatbot-2.md): while True: - [LlamaIndex and Cohere's Models](llamaindex-and-coheres-models.md): Learn how to use Cohere and LlamaIndex together to generate responses based on data. - [Generate Embeddings](generate-embeddings.md): embeddings = embed_model.get_text_embedding("Welcome to Cohere!") - [Print embeddings](print-embeddings.md): print(len(embeddings)) - [create index (we are using an example page from Cohere's docs)](create-index-we-are-using-an-example-page-from-coheres-docs.md): documents = SimpleWebPageReader(html_to_text=True).load_data( - [create reranker](create-reranker.md): cohere_rerank = CohereRerank( - [query the index](query-the-index.md): query_engine = index.as_query_engine( - [generate a response](generate-a-response-2.md): response = query_engine.query( - [To view the source documents](to-view-the-source-documents.md): from llama_index.core.response.pprint_utils import pprint_response - [Create the embedding model](create-the-embedding-model.md): embed_model = CohereEmbedding( - [Create the service context with the cohere model for generation and embedding model](create-the-service-context-with-the-cohere-model-for-generation-and-embedding-mo.md): Settings.llm = Cohere( - [create index (we are using an example page from Cohere's docs)](create-index-we-are-using-an-example-page-from-coheres-docs-2.md): documents = SimpleWebPageReader(html_to_text=True).load_data( - [Create a cohere reranker](create-a-cohere-reranker.md): cohere_rerank = CohereRerank( - [Create the query engine](create-the-query-engine.md): query_engine = index.as_query_engine( - [Generate the response](generate-the-response.md): response = query_engine.query("What is Cohere's Embed model?") - [Define tools](define-tools.md): def multiply(a: int, b: int) -> int: - [Define LLM](define-llm.md): llm = Cohere(api_key="COHERE_API_KEY", model="command-a-03-2025") - [Create agent](create-agent.md): agent = FunctionCallingAgent.from_tools( - [Run agent](run-agent.md): response = await agent.achat("What is (121 * 3) + (5 * 8)?") - [Deployment Options - Overview](deployment-options-overview.md): This page provides an overview of the available options for deploying Cohere's models. - [Cohere SDK Cloud Platform Compatibility](cohere-sdk-cloud-platform-compatibility.md): This page describes various places you can use Cohere's SDK. - [Private Deployment Overview](private-deployment-overview.md): This page provides an overview of private deployments of Cohere's models. - [Private Deployment – Setting Up](private-deployment-setting-up.md): This page describes the setup required for private deployments of Cohere's models. - [Deploying Models in Private Environments](deploying-models-in-private-environments.md): Learn how to pull and test Cohere's container images using a license with Docker and Kubernetes. - [once the pod is running](once-the-pod-is-running.md): kubectl port-forward svc/${APP} 8080:8080 - [Handling connection for 8080](handling-connection-for-8080.md): Leave that running in the background, and up a new terminal session to execute a test request. In the next few sectio... - [AWS Private Deployment Guide (EC2 and EKS)](aws-private-deployment-guide-ec2-and-eks.md): Deploying Cohere models in AWS via EC2 or EKS for enhanced security, compliance, and control. - [Private Deployment Usage](private-deployment-usage.md): This page describes how to use Cohere's SDK to access privately deployed Cohere models. - [Cohere on Amazon Web Services (AWS)](cohere-on-amazon-web-services-aws.md): Access Cohere's language models on AWS with customization options through Amazon SageMaker and Amazon Bedrock. - [Cohere Models on Amazon Bedrock](cohere-models-on-amazon-bedrock.md): This document provides a guide for using Cohere's models on Amazon Bedrock. - [Input parameters for embed. In this example we are embedding hacker news post titles.](input-parameters-for-embed-in-this-example-we-are-embedding-hacker-news-post-tit.md): texts = [ - [Invoke the model and print the response](invoke-the-model-and-print-the-response.md): result = co.embed( - [An Amazon SageMaker Setup Guide](an-amazon-sagemaker-setup-guide.md): This document will guide you through enabling development teams to access Cohere’s offerings on Amazon SageMaker. - [Input parameters for embed. In this example we are embedding hacker news post titles.](input-parameters-for-embed-in-this-example-we-are-embedding-hacker-news-post-tit-2.md): texts = [ - [Invoke the model and print the response](invoke-the-model-and-print-the-response-2.md): result = co.embed( - [Invoke the model and print the response](invoke-the-model-and-print-the-response-3.md): result = co.chat(message="Write a LinkedIn post about starting a career in tech:", - [Set up your documents and query](set-up-your-documents-and-query.md): query = "YOUR QUERY" - [Invoke the model and print the response](invoke-the-model-and-print-the-response-4.md): results = co.rerank( - [Deploy Finetuned Command Models from AWS Marketplace](deploy-finetuned-command-models-from-aws-marketplace.md): This document provides a guide for bringing your own finetuned models to Amazon SageMaker. - [Change "" to your own AWS profile name](change-aws-profile-to-your-own-aws-profile-name.md): os.environ["AWS_PROFILE"] = "" - [Get the arn of the bring your own finetuning algorithm by region](get-the-arn-of-the-bring-your-own-finetuning-algorithm-by-region.md): cohere_package = "cohere-command-r-v2-byoft-8370167e649c32a1a5f00267cd334c2c" - [The local directory of your adapter weights. No need to specify this, if you bring your own merged weights](the-local-directory-of-your-adapter-weights-no-need-to-specify-this-if-you-bring.md): adapter_weights_dir = "" - [The local directory you want to save the merged weights. Or the local directory of your own merged weights, if you bring your own merged weights](the-local-directory-you-want-to-save-the-merged-weights-or-the-local-directory-o.md): merged_weights_dir = "" - [The S3 directory you want to save the merged weights](the-s3-directory-you-want-to-save-the-merged-weights.md): s3_checkpoint_dir = "" - [The S3 directory you want to save the exported TensorRT-LLM engine. Make sure you do not reuse the same S3 directory across multiple runs](the-s3-directory-you-want-to-save-the-exported-tensorrt-llm-engine-make-sure-you.md): s3_output_dir = "" - [The name of the export](the-name-of-the-export.md): export_name = "" - [The name of the SageMaker endpoint](the-name-of-the-sagemaker-endpoint.md): endpoint_name = "" - [The instance type for export and inference. Now "ml.p4de.24xlarge" and "ml.p5.48xlarge" are supported](the-instance-type-for-export-and-inference-now-mlp4de24xlarge-and-mlp548xlarge-a.md): instance_type = "" - [Get the merged model from adapter weights](get-the-merged-model-from-adapter-weights.md): merged_model = load_and_merge_model("CohereForAI/c4ai-command-r-08-2024", adapter_weights_dir) - [Save the merged weights to your local directory](save-the-merged-weights-to-your-local-directory.md): save_hf_model(merged_weights_dir, merged_model) - [If the endpoint is already deployed, you can directly connect to it](if-the-endpoint-is-already-deployed-you-can-directly-connect-to-it.md): co.sagemaker_finetuning.connect_to_endpoint(endpoint_name=endpoint_name) - [Cohere on the Microsoft Azure Platform](cohere-on-the-microsoft-azure-platform.md): This page describes how to work with Cohere models on Microsoft Azure. - [Configure payload data sending to API endpoint](configure-payload-data-sending-to-api-endpoint.md): data = { - [Replace the url with your API endpoint](replace-the-url-with-your-api-endpoint.md): url = ( - [Replace this with the key for the endpoint](replace-this-with-the-key-for-the-endpoint.md): api_key = "your-auth-key" - [Configure payload data sending to API endpoint](configure-payload-data-sending-to-api-endpoint-2.md): data = {"input": ["hi"]} - [Replace the url with your API endpoint](replace-the-url-with-your-api-endpoint-2.md): url = " - [Replace this with the key for the endpoint](replace-this-with-the-key-for-the-endpoint-2.md): api_key = "your-auth-key" - [For Command models](for-command-models.md): co_chat = cohere.Client( - [For Embed models](for-embed-models.md): co_embed = cohere.Client( - [For Rerank models](for-rerank-models.md): co_rerank = cohere.Client( - [Cohere on Oracle Cloud Infrastructure (OCI)](cohere-on-oracle-cloud-infrastructure-oci.md): This page describes how to work with Cohere models on Oracle Cloud Infrastructure (OCI) - [Model Vault](model-vault.md): This document provides a guide for using Cohere's new Model Vault functionality. - [Cohere Cookbooks: Build AI Agents and Solutions](cohere-cookbooks-build-ai-agents-and-solutions.md): Get started with Cohere's cookbooks to build agents, QA bots, perform searches, and more, all organized by category. - [Welcome to LLM University!](welcome-to-llm-university.md): LLM University (LLMU) offers in-depth, practical NLP and LLM training. Ideal for all skill levels. Learn, build, and ... - [Build an Onboarding Assistant with Cohere!](build-an-onboarding-assistant-with-cohere.md): This page describes how to build an onboarding assistant with Cohere's large language models. - [Get your API key here: https://dashboard.cohere.com/api-keys](get-your-api-key-here-httpsdashboardcoherecomapi-keys.md): co = cohere.ClientV2(api_key="YOUR_COHERE_API_KEY") - [Cohere Text Generation Tutorial](cohere-text-generation-tutorial.md): This page walks through how Cohere's generation models work and how to use them. - [Get your free API key: https://dashboard.cohere.com/api-keys](get-your-free-api-key-httpsdashboardcoherecomapi-keys.md): co = cohere.ClientV2(api_key="COHERE_API_KEY") - [Add the user message](add-the-user-message-3.md): message = "I'm joining a new startup called Co1t today. Could you help me write a short introduction message to my te... - [Generate the response](generate-the-response-2.md): response = co.chat( - [messages=[cohere.UserMessage(content=message)])](messagescohereusermessagecontentmessage.md): print(response.message.content[0].text) - [Add the user message](add-the-user-message-4.md): message = "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message t... - [Generate the response](generate-the-response-3.md): response = co.chat( - [messages=[cohere.UserMessage(content=message)])](messagescohereusermessagecontentmessage-2.md): print(response.message.content[0].text) - [Add the user message](add-the-user-message-5.md): user_input = ( - [Create a prompt containing example outputs](create-a-prompt-containing-example-outputs.md): message = f"""Write a ticket title for the following user request: - [Generate the response](generate-the-response-4.md): response = co.chat( - [Add the user message](add-the-user-message-6.md): message = "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message t... - [Generate the response](generate-the-response-5.md): response = co.chat( - [Add the user message](add-the-user-message-7.md): message = "I like learning about the industrial revolution and how it shapes the modern world. How I can introduce my... - [Generate the response multiple times by specifying a low temperature value](generate-the-response-multiple-times-by-specifying-a-low-temperature-value.md): for idx in range(3): - [Add the user message](add-the-user-message-8.md): message = "I like learning about the industrial revolution and how it shapes the modern world. How I can introduce my... - [Generate the response multiple times by specifying a low temperature value](generate-the-response-multiple-times-by-specifying-a-low-temperature-value-2.md): for idx in range(3): - [Add the user message](add-the-user-message-9.md): user_input = ( - [Generate the response multiple times by adding the JSON schema](generate-the-response-multiple-times-by-adding-the-json-schema.md): response = co.chat( - [Add the user message](add-the-user-message-10.md): message = "I'm joining a new startup called Co1t today. Could you help me write a one-sentence introduction message t... - [Generate the response by streaming it](generate-the-response-by-streaming-it.md): response = co.chat_stream( - [Building a Chatbot with Cohere](building-a-chatbot-with-cohere.md): This page describes building a generative-AI powered chatbot with Cohere. - [Get your free API key: https://dashboard.cohere.com/api-keys](get-your-free-api-key-httpsdashboardcoherecomapi-keys-2.md): co = cohere.ClientV2(api_key="COHERE_API_KEY") - [Create a custom system instruction that guides all of the Assistant's responses](create-a-custom-system-instruction-that-guides-all-of-the-assistants-responses.md): system_instruction = """## Task and Context - [Send messages to the model](send-messages-to-the-model.md): response = co.chat( - [user turn 1](user-turn-1.md): messages.append( - [assistant turn 1](assistant-turn-1.md): messages.append( - [user turn 2](user-turn-2.md): messages.append({"role": "user", "content": "Who founded co1t?"}) - [assistant turn 2](assistant-turn-2.md): messages.append(response.message) - [Semantic Search with Cohere Models](semantic-search-with-cohere-models.md): This is a tutorial describing how to leverage Cohere's models for semantic search. - [pip install cohere](pip-install-cohere.md): import cohere - [Get your free API key: https://dashboard.cohere.com/api-keys](get-your-free-api-key-httpsdashboardcoherecomapi-keys-3.md): co = cohere.ClientV2(api_key="COHERE_API_KEY") - [Define the documents](define-the-documents.md): faqs_long = [ - [Embed the documents](embed-the-documents-3.md): doc_emb = co.embed( - [Add the user query](add-the-user-query-3.md): query = "How do I stay connected to what's happening at the company?" - [Embed the query](embed-the-query-3.md): query_emb = co.embed( - [Compute dot product similarity and display results](compute-dot-product-similarity-and-display-results-2.md): def return_results(query_emb, doc_emb, documents): - [Define the documents](define-the-documents-2.md): faqs_short_fr = [ - [Embed the documents](embed-the-documents-4.md): doc_emb = co.embed( - [Add the user query](add-the-user-query-4.md): query = "What's your remote-working policy?" - [Embed the query](embed-the-query-4.md): query_emb = co.embed( - [Compute dot product similarity and display results](compute-dot-product-similarity-and-display-results-3.md): return_results(query_emb, doc_emb, documents) - [Changing embedding compression types](changing-embedding-compression-types.md): Semantic search over large datasets can require a lot of memory, which is expensive to host in a vector database. Cha... - [Embed the documents with the given embedding types](embed-the-documents-with-the-given-embedding-types.md): doc_emb = co.embed( - [Add the user query](add-the-user-query-5.md): query = "How do I stay connected to what's happening at the company?" - [Embed the query](embed-the-query-5.md): query_emb = co.embed( - [Compute dot product similarity and display results](compute-dot-product-similarity-and-display-results-4.md): return_results(query_emb.float, doc_emb.float, faqs_long) - [Compute dot product similarity and display results](compute-dot-product-similarity-and-display-results-5.md): return_results(query_emb.int8, doc_emb.int8, documents) - [Master Reranking with Cohere Models](master-reranking-with-cohere-models.md): This page contains a tutorial on using Cohere's ReRank models. - [Get your free API key: https://dashboard.cohere.com/api-keys](get-your-free-api-key-httpsdashboardcoherecomapi-keys-4.md): co = cohere.ClientV2(api_key="COHERE_API_KEY") - [Define the documents](define-the-documents-3.md): faqs = [ - [Add the user query](add-the-user-query-6.md): query = "Are there fitness-related perks?" - [Rerank the documents](rerank-the-documents.md): results = co.rerank( - [Display the reranking results](display-the-reranking-results.md): def return_results(results, documents): - [Define the documents](define-the-documents-4.md): emails = [ - [Convert the documents to YAML format](convert-the-documents-to-yaml-format.md): yaml_docs = [yaml.dump(doc, sort_keys=False) for doc in emails] - [Add the user query](add-the-user-query-7.md): query = "Any email about check ins?" - [Rerank the documents](rerank-the-documents-2.md): results = co.rerank( - [Create a demo CSV file](create-a-demo-csv-file.md): data = """name,role,join_date,email,status - [Load the CSV file](load-the-csv-file.md): df = pd.read_csv(data_csv) - [Define the documents](define-the-documents-5.md): employees = df.to_dict("records") - [Convert the documents to YAML format](convert-the-documents-to-yaml-format-2.md): yaml_docs = [yaml.dump(doc, sort_keys=False) for doc in employees] - [Add the user query](add-the-user-query-8.md): query = "Any full-time product designers who joined recently?" - [Rerank the documents](rerank-the-documents-3.md): results = co.rerank( - [Define the query](define-the-query.md): query = "هل هناك مزايا تتعلق باللياقة البدنية؟" # Are there fitness benefits? - [Rerank the documents](rerank-the-documents-4.md): results = co.rerank( - [Building RAG models with Cohere](building-rag-models-with-cohere.md): This page walks through building a retrieval-augmented generation model with Cohere. - [pip install cohere](pip-install-cohere-2.md): import cohere - [Get your free API key: https://dashboard.cohere.com/api-keys](get-your-free-api-key-httpsdashboardcoherecomapi-keys-5.md): co = cohere.ClientV2(api_key="COHERE_API_KEY") - [Add the user query](add-the-user-query-9.md): query = "Are there health benefits?" - [Generate the response](generate-the-response-6.md): response = co.chat( - [Display the response](display-the-response.md): print(response.message.content[0].text) - [Display the citations and source documents](display-the-citations-and-source-documents.md): if response.message.citations: - [Define the documents](define-the-documents-6.md): faqs_long = [ - [Embed the documents](embed-the-documents-5.md): doc_emb = co.embed( - [Add the user query](add-the-user-query-10.md): query = "How to get to know my teammates" - [Note: For simplicity, we are assuming only one query generated. For actual implementations, you will need to perform search for each query.](note-for-simplicity-we-are-assuming-only-one-query-generated-for-actual-implemen.md): queries_for_search = generate_search_queries(query)[0] - [Embed the search query](embed-the-search-query.md): query_emb = co.embed( - [Compute dot product similarity and display results](compute-dot-product-similarity-and-display-results-6.md): n = 5 - [Rerank the documents](rerank-the-documents-5.md): results = co.rerank( - [Display the reranking results](display-the-reranking-results-2.md): for idx, result in enumerate(results.results): - [Generate the response](generate-the-response-7.md): response = co.chat( - [Display the response](display-the-response-2.md): print(response.message.content[0].text) - [Display the citations and source documents](display-the-citations-and-source-documents-2.md): if response.message.citations: - [Building a Generative AI Agent with Cohere](building-a-generative-ai-agent-with-cohere.md): This page describes building a generative-AI powered agent with Cohere. - [Get your free API key: https://dashboard.cohere.com/api-keys](get-your-free-api-key-httpsdashboardcoherecomapi-keys-6.md): co = cohere.ClientV2(api_key="COHERE_API_KEY") - [Create the tools](create-the-tools.md): def search_faqs(query): - [Define the tools](define-the-tools.md): tools = [ - [Create custom system message](create-custom-system-message.md): system_message = """## Task and Context - [Step 1: Get user message](step-1-get-user-message.md): message = "Is there any message about getting setup with IT?" - [Add the system and user messages to the chat history](add-the-system-and-user-messages-to-the-chat-history.md): messages = [ - [Step 2: Tool planning and calling](step-2-tool-planning-and-calling.md): response = co.chat( - [Step 3: Tool execution](step-3-tool-execution.md): for tc in response.message.tool_calls: - [Step 4: Response and citation generation](step-4-response-and-citation-generation.md): response = co.chat( - [Append assistant response to the chat history](append-assistant-response-to-the-chat-history.md): messages.append( - [Print final response](print-final-response-2.md): print("Response:") - [Print citations (if any)](print-citations-if-any-2.md): if response.message.citations: - [Multi-step tool use](multi-step-tool-use.md): The model can execute more complex tasks in tool use – tasks that require tool calls to happen in a sequence. This is... - [Building Agentic RAG with Cohere](building-agentic-rag-with-cohere.md): Hands-on tutorials on building agentic RAG applications with Cohere - [Routing Queries to Data Sources](routing-queries-to-data-sources.md): Build an agentic RAG system that routes queries to the most relevant tools based on the query's nature. - [Generate Parallel Queries for Better RAG Retrieval](generate-parallel-queries-for-better-rag-retrieval.md): Build an agentic RAG system that can expand a user query into a more optimized set of queries for retrieval. - [Performing Tasks Sequentially with Cohere's RAG](performing-tasks-sequentially-with-coheres-rag.md): Build an agentic RAG system that can handle user queries that require tasks to be performed in a sequence. - [Generating Multi-Faceted Queries](generating-multi-faceted-queries.md): Build a system that generates multi-faceted queries to capture the full intent of a user's request. - [Tool name: search_code_examples | Parameters: {"query":"RAG code examples"}](tool-name-search-code-examples-parameters-queryrag-code-examples.md): QUESTION: - [Tool name: search_code_examples | Parameters: {"programming_language":"js","query":"..."}](tool-name-search-code-examples-parameters-programming-languagejsquery.md): QUESTION: - [Tool name: search_code_examples | Parameters: {"endpoints":["embed","rerank"],"query":"..."}](tool-name-search-code-examples-parameters-endpointsembedrerankquery.md): QUESTION: - [Tool name: search_code_examples | Parameters: {"endpoints":["chat"],"programming_language":"py","query":"..."}](tool-name-search-code-examples-parameters-endpointschatprogramming-languagepyque.md): QUESTION: - [Querying Structured Data (Tables)](querying-structured-data-tables.md): Build an agentic RAG system that can query structured data (tables). - [Answer: 0.63](answer-063.md): Question: - [Answer: 4.8](answer-48.md): Question: - [Answer: extract_names (106.25), draft_email (245.75), summarize_article (355.75)](answer-extract-names-10625-draft-email-24575-summarize-article-35575.md): Question: - [Querying Structured Data (SQL)](querying-structured-data-sql.md): Build an agentic RAG system that can query structured data (SQL). - [Create a connection to a new SQLite database (or connect to an existing one)](create-a-connection-to-a-new-sqlite-database-or-connect-to-an-existing-one.md): conn = sqlite3.connect("evaluation_results.db") - [Execute the CREATE TABLE command](execute-the-create-table-command.md): cursor.execute( - [Execute the INSERT commands](execute-the-insert-commands.md): data = [ - [Commit the changes and close the connection](commit-the-changes-and-close-the-connection.md): conn.commit() - [Answer: 0.63](answer-063-2.md): Question: - [Answer: 4.8](answer-48-2.md): Question: - [Answer: extract_names (106.25), draft_email (245.75), summarize_article (355.75)](answer-extract-names-10625-draft-email-24575-summarize-article-35575-2.md): Question: - [Introduction to Cohere on Azure AI Foundry](introduction-to-cohere-on-azure-ai-foundry.md): An introduction to Cohere on Azure AI Foundry, a fully managed service by Azure (API v2). - [Text generation - Cohere on Azure AI Foundry](text-generation-cohere-on-azure-ai-foundry.md): A guide for performing text generation with Cohere's Command models on Azure AI Foundry (API v2). - [%pip install cohere](pip-install-cohere-3.md): import cohere - [Technical support FAQ](technical-support-faq.md): faq_tech_support = """- Question: How do I set up my new smartphone with my mobile plan? - [FAQs](faqs.md): {faq_tech_support}""" - [Define a system message](define-a-system-message.md): system_message = """## Task and Context - [Run the chatbot](run-the-chatbot-3.md): def run_chatbot(message, messages=None): - [Semantic search - Cohere on Azure AI Foundry](semantic-search-cohere-on-azure-ai-foundry.md): A guide for performing text semantic search with Cohere's Embed models on Azure AI Foundry (API v2). - [%pip install cohere hnswlib](pip-install-cohere-hnswlib.md): import pandas as pd - [Inspect dataset](inspect-dataset.md): df.head(5) - [Ensure there is no duplicated text in the headers](ensure-there-is-no-duplicated-text-in-the-headers.md): def remove_duplicates(text): - [Keep only selected languages](keep-only-selected-languages.md): languages = ["English", "Spanish", "Danish"] - [Pick the top 80 longest articles](pick-the-top-80-longest-articles.md): df["text_length"] = df["text"].str.len() - [Language distribution](language-distribution.md): top_80_df["lang"].value_counts() - [Embed documents](embed-documents.md): docs = top_80_df["text"].to_list() - [Create a search index](create-a-search-index.md): index = hnswlib.Index(space="ip", dim=1536) - [Retrieval of 4 closest docs to query](retrieval-of-4-closest-docs-to-query.md): def retrieval(query): - [Reranking - Cohere on Azure AI Foundry](reranking-cohere-on-azure-ai-foundry.md): A guide for performing reranking with Cohere's Reranking models on Azure AI Foundry (API v2). - [%pip install cohere](pip-install-cohere-4.md): import cohere - [Define the documents](define-the-documents-7.md): emails = [ - [Add the user query](add-the-user-query-11.md): query = "Any email about check ins?" - [Rerank the documents](rerank-the-documents-6.md): results = co.rerank( - [Retrieval augmented generation (RAG) - Cohere on Azure AI Foundry](retrieval-augmented-generation-rag-cohere-on-azure-ai-foundry.md): A guide for performing retrieval augmented generation (RAG) with Cohere's Command models on Azure AI Foundry (API v2). - [%pip install cohere hnswlib unstructured](pip-install-cohere-hnswlib-unstructured.md): import cohere - [Create an instance of the Vectorstore class with the given sources](create-an-instance-of-the-vectorstore-class-with-the-given-sources.md): vectorstore = Vectorstore(raw_documents) - [Tool use & agents - Cohere on Azure AI Foundry](tool-use-agents-cohere-on-azure-ai-foundry.md): A guide for using tool use and building agents with Cohere's Command models on Azure AI Foundry (API v2). - [%pip install cohere](pip-install-cohere-5.md): import cohere - [Usage Policy](usage-policy.md): Developers must outline and get approval for their use case to access the Cohere API, understanding the models and li... - [Command R and Command R+ Model Card](command-r-and-command-r-model-card.md): This doc provides guidelines for using Cohere generation models ethically and constructively. - [Cohere Labs Acceptable Use Policy](cohere-labs-acceptable-use-policy.md): "Promoting safe and ethical use of generative AI with guidelines to prevent misuse and abuse." - [How to Start with the Cohere Toolkit](how-to-start-with-the-cohere-toolkit.md): Build and deploy RAG applications quickly with the Cohere Toolkit, which offers pre-built front-end and back-end comp... - [The Cohere Datasets API (and How to Use It)](the-cohere-datasets-api-and-how-to-use-it.md): Learn about the Dataset API, including its file size limits, data retention, creation, validation, metadata, and more... - [Upload a dataset for embed jobs](upload-a-dataset-for-embed-jobs.md): ds = co.datasets.create( - [wait for the dataset to finish validation](wait-for-the-dataset-to-finish-validation.md): print(co.wait(ds)) - [fetch the dataset by ID](fetch-the-dataset-by-id.md): my_dataset_response = co.datasets.get(id="") - [print each entry in the dataset](print-each-entry-in-the-dataset.md): for record in my_dataset: - [save the dataset as jsonl](save-the-dataset-as-jsonl.md): co.utils.save_dataset( - [or save the dataset as csv](or-save-the-dataset-as-csv.md): co.utils.save_dataset( - [Help Us Improve The Cohere Docs](help-us-improve-the-cohere-docs.md): Contribute to our docs content, stored in the cohere-developer-experience repo; we welcome your pull requests! - [Working with Cohere's API and SDK](working-with-coheres-api-and-sdk.md): Cohere's NLP platform provides customizable large language models and tools for developers to build AI applications. - [Teams and Roles on the Cohere Platform](teams-and-roles-on-the-cohere-platform.md): The document outlines how to work in teams on the Cohere platform, including inviting others, managing roles, and acc... - [Errors (status codes and description)](errors-status-codes-and-description.md): Understand Cohere's HTTP response codes and how to handle errors in various programming languages. - [Http status codes](http-status-codes.md): 400 responses are sent when the body of the request is not valid. This can happen when required fields are missing, o... - [Migrating From API v1 to API v2](migrating-from-api-v1-to-api-v2.md): The document serves as a reference for developers looking to update their existing Cohere API v1 implementations to t... - [instantiating the old client](instantiating-the-old-client.md): co_v1 = cohere.Client(api_key="") - [instantiating the new client](instantiating-the-new-client.md): co_v2 = cohere.ClientV2(api_key="") - [General](general.md): * v2:`model`is a required field for Embed, Rerank, Classify, and Chat. - [Embed](embed.md): * v2:`embedding_types`is a required field for Embed. - [Chat](chat.md): * Message structure: - [RAG](rag.md): * v1: the`documents`parameter supports a list of objects with multiple fields per document. - [Define the documents](define-the-documents-8.md): documents_v1 = [ - [The user query](the-user-query.md): message = "Are there fitness-related benefits?" - [Generate the response](generate-the-response-8.md): res_v1 = co_v1.chat( - [Define the documents](define-the-documents-9.md): documents_v2 = [ - [The user query](the-user-query-2.md): message = "Are there fitness-related benefits?" - [Generate the response](generate-the-response-9.md): res_v2 = co_v2.chat( - [Yes, there are fitness-related benefits. We offer gym memberships, on-site yoga classes, and comprehensive health insurance.](yes-there-are-fitness-related-benefits-we-offer-gym-memberships-on-site-yoga-cla.md): print(res_v1.citations) - [Yes, we offer gym memberships, on-site yoga classes, and comprehensive health insurance.](yes-we-offer-gym-memberships-on-site-yoga-classes-and-comprehensive-health-insur.md): print(res_v2.message.citations) - [Any search engine can be used. This example uses the Tavily API.](any-search-engine-can-be-used-this-example-uses-the-tavily-api.md): from tavily import TavilyClient - [Create a web search function](create-a-web-search-function.md): def web_search(queries: list[str]) -> list[dict]: - [Define the web search tool](define-the-web-search-tool.md): web_search_tool = [ - [Define a system message to optimize search query generation](define-a-system-message-to-optimize-search-query-generation-2.md): instructions = "Write a search query that will find helpful information for answering the user's question accurately.... - [Generate search queries (if any)](generate-search-queries-if-any-2.md): response = co_v2.chat( - [Tool use](tool-use.md): * v1: uses Python types to define tools. - [Unsupported features in v2](unsupported-features-in-v2.md): The following v1 features are not supported in v2: - [Using Cohere models via the OpenAI SDK](using-cohere-models-via-the-openai-sdk.md): The document serves as a guide for Cohere's Compatibility API, which allows developers to seamlessly use Cohere's mod... - [Chat](chat-2.md): POST - [Chat with Streaming](chat-with-streaming.md): POST - [Rerank API (v2)](rerank-api-v2.md): POST - [Embed API (v2)](embed-api-v2.md): POST - [Create an Embed Job](create-an-embed-job.md): POST - [start an embed job](start-an-embed-job.md): job = co.embed_jobs.create( - [poll the server until the job is complete](poll-the-server-until-the-job-is-complete.md): response = co.wait(job) - [List Embed Jobs](list-embed-jobs.md): GET - [list embed jobs](list-embed-jobs-2.md): response = co.embed_jobs.list() - [Fetch an Embed Job](fetch-an-embed-job.md): GET - [get embed job](get-embed-job.md): response = co.embed_jobs.get("job_id") - [Cancel an Embed Job](cancel-an-embed-job.md): POST - [cancel an embed job](cancel-an-embed-job-2.md): co.embed_jobs.cancel("job_id") - [Create a Dataset](create-a-dataset.md): POST - [upload a dataset](upload-a-dataset.md): my_dataset = co.datasets.create( - [wait for validation to complete](wait-for-validation-to-complete.md): response = co.wait(my_dataset) - [List Datasets](list-datasets.md): GET - [get list of datasets](get-list-of-datasets.md): response = co.datasets.list() - [Get Dataset Usage](get-dataset-usage.md): GET - [get usage](get-usage.md): response = co.datasets.get_usage() - [Get a Dataset](get-a-dataset.md): GET - [get dataset](get-dataset.md): response = co.datasets.get(id=">") - [Delete a Dataset](delete-a-dataset.md): DELETE - [delete dataset](delete-dataset.md): co.datasets.delete("id") - [Tokenize](tokenize.md): POST - [Detokenize](detokenize.md): POST - [Get a Model](get-a-model.md): GET - [List Models](list-models.md): GET - [Classify](classify.md): POST - [List Connectors](list-connectors.md): GET - [Create a Connector](create-a-connector.md): POST - [Get a Connector](get-a-connector.md): GET - [Update a Connector](update-a-connector.md): PATCH - [Delete a Connector](delete-a-connector.md): DELETE - [Authorize with oAuth](authorize-with-oauth.md): POST - [Lists fine-tuned models.](lists-fine-tuned-models.md): GET - [Trains and deploys a fine-tuned model.](trains-and-deploys-a-fine-tuned-model.md): POST - [Updates a fine-tuned model.](updates-a-fine-tuned-model.md): PATCH - [Returns a fine-tuned model by ID.](returns-a-fine-tuned-model-by-id.md): GET - [Deletes a fine-tuned model.](deletes-a-fine-tuned-model.md): DELETE - [Fetch history of statuses for a fine-tuned model.](fetch-history-of-statuses-for-a-fine-tuned-model.md): GET - [Retrieve training metrics for fine-tuned models.](retrieve-training-metrics-for-fine-tuned-models.md): GET - [Cohere's Rerank v4.0 Model is Here!](coheres-rerank-v40-model-is-here.md): Release announcment for Rerank 4.0 - our new state of the art model for ranking. - [Announcing Major Command Deprecations](announcing-major-command-deprecations.md): This announcement covers a series of major deprecations, including of classic Command models, several parameters, and... - [Announcing Cohere's Command A Translate Model](announcing-coheres-command-a-translate-model.md): This announcement covers the release of Command A Translate, Cohere's most powerful translation model. - [Announcing Cohere's Command A Reasoning Model](announcing-coheres-command-a-reasoning-model.md): This announcement covers the release of Command A Reasoning, Cohere's first model able to engage in thinking and reas... - [Announcing Cohere's Command A Vision Model](announcing-coheres-command-a-vision-model.md): This announcement covers the release of Command A Vision, Cohere's first model able to understand and interpret image... - [Announcing Cutting-Edge Cohere Models on OCI](announcing-cutting-edge-cohere-models-on-oci.md): This announcement covers the release of Command A, Rerank v3.5, and Embed v3.0 multimodal on Oracle Cloud Infrastruct... - [Announcing Embed Multimodal v4](announcing-embed-multimodal-v4.md): Release of Embed Multimodal v4, a performant search model, with Matryoshka embeddings and a 128k context length. - [Announcing Command A](announcing-command-a.md): Release of Command A, a performant model suited for tool use, RAG, agents, and multilingual uses, with 111 billion pa... - [Our Groundbreaking Multimodal Model, Aya Vision, is Here!](our-groundbreaking-multimodal-model-aya-vision-is-here.md): Release announcement for the new multimodal Aya Vision model - [Cohere Releases Arabic-Optimized Command Model!](cohere-releases-arabic-optimized-command-model.md): Release announcement for the Command R7B Arabic model - [Format message with the c4ai-command-r7b-12-2024 chat template](format-message-with-the-c4ai-command-r7b-12-2024-chat-template.md): messages = [{"role": "user", "content": "مرحبا، كيف حالك؟"}] - [Define conversation input](define-conversation-input.md): conversation = [ - [Define documents for retrieval-based generation](define-documents-for-retrieval-based-generation.md): documents = [ - [Get the RAG prompt](get-the-rag-prompt.md): input_prompt = tokenizer.apply_chat_template( - [Tokenize the prompt](tokenize-the-prompt.md): input_ids = tokenizer.encode_plus(input_prompt, return_tensors="pt") - [Cohere via OpenAI SDK Using Compatibility API](cohere-via-openai-sdk-using-compatibility-api.md): With the Compatibility API, you can use Cohere models via the OpenAI SDK without major refactoring. - [Cohere's Rerank v3.5 Model is on Azure AI Foundry!](coheres-rerank-v35-model-is-on-azure-ai-foundry.md): Release announcement for the ability to work with Cohere Rerank v3.5 models in the Azure's AI Foundry. - [Cohere's Rerank v3.5 Model is on Azure AI Foundry!](coheres-rerank-v35-model-is-on-azure-ai-foundry-2.md): Release announcement for the ability to work with Cohere Rerank v3.5 models in the Azure's AI Foundry. - [Deprecation of Classify via default Embed Models](deprecation-of-classify-via-default-embed-models.md): Usage of Classify endpoint via the default Embed models is now deprecated. Usage of Classify endpoint via a fine-tune... - [Cohere's Multimodal Embedding Models are on Bedrock!](coheres-multimodal-embedding-models-are-on-bedrock.md): Release announcement for the ability to work with multimodal image models on the Amazon Bedrock platform. - [Aya Expanse is Available on WhatsApp!](aya-expanse-is-available-on-whatsapp.md): Release announcement for the ability to chat with Aya Expanse on WhatsApp - [Announcing Command R7b](announcing-command-r7b.md): Release announcment for Command R 7B - our fastest, lightest, and last Command R model. - [Announcing Rerank-v3.5](announcing-rerank-v35.md): Release announcment for Rerank 3.5 - our new state of the art model for ranking. - [Structured Outputs support for tool use](structured-outputs-support-for-tool-use.md): Structured Outputs now supports both JSON and tool use scenarios. - [Embed v3.0 Models are now Multimodal](embed-v30-models-are-now-multimodal.md): Launch of multimodal embeddings for our Embed models, plus some code to help get started. - [Fine-Tuning Now Available for Command R 08-2024](fine-tuning-now-available-for-command-r-08-2024.md): Launch of fine-tuning for Command R 08-2024 and other new fine-tuning features. - [New Embed, Rerank, Chat, and Classify APIs](new-embed-rerank-chat-and-classify-apis.md): Introducing improvements to our Chat, Classify, Embed, and Rerank APIs in a major version upgrade, making it easier a... - [Refreshed Command R and R+ models now on Azure](refreshed-command-r-and-r-models-now-on-azure.md): Introducing our improved Command models are available on the Azure cloud computing platform. - [Command models get an August refresh](command-models-get-an-august-refresh.md): We're excited to announce updates to our Command R and R+ models, offering improved performance, new features, and more. - [Force JSON object response format](force-json-object-response-format.md): Generate outputs in JSON objects with the new 'response_format' parameter, now available with the 'command-nightly' m... - [Release Notes for June 10th 2024](release-notes-for-june-10th-2024.md): Get started with multi-step tool use, explore new docs, and learn about billing changes in Cohere's Chat API. - [Advanced Retrieval Launch release](advanced-retrieval-launch-release.md): Rerank 3 offers improved performance and inference speed for long and short documents with a context length of 4096. - [Cohere Python SDK v5.2.0 release](cohere-python-sdk-v520-release.md): Stay up to date with our Python SDK update, including local tokenizer defaults and new required fields. - [Command R: Retrieval-Augmented Generation at Scale](command-r-retrieval-augmented-generation-at-scale.md): Command R: Retrieval Augmented Generation at scale. - [Fine-tuning has been added to the Python SDK](fine-tuning-has-been-added-to-the-python-sdk.md): Stay up-to-date with Cohere's Python SDK by checking out the new`fine_tuning`feature and its functions. - [Cohere Python SDK v5.0.0 release](cohere-python-sdk-v500-release.md): Stay up-to-date with our latest Python SDK release and learn about deprecated functions and migration instructions. - [Release Notes January 22, 2024](release-notes-january-22-2024.md): Discover new AI capabilities with Cohere's latest features, including improved fine-tuning, Embed Jobs API, and multi... - [Release Notes September 29th 2023](release-notes-september-29th-2023.md): Experience the future of generative AI with co.chat() and explore the power of retrieval-augmented generation for gro... - [Release Notes August 8th 2023 (Changelog)](release-notes-august-8th-2023-changelog.md): Unlock improved reasoning and conversation with Command R+, now featuring Okta OIDC support and an enhanced finetunin... - [Release Notes June 28th 2023 (Changelog)](release-notes-june-28th-2023-changelog.md): The latest Command model update brings enhanced code, conversation, and reasoning, along with new API features and us... - [New Maximum Number of Input Documents for Rerank](new-maximum-number-of-input-documents-for-rerank.md): Stay up to date with our latest changes to co.rerank, now with an improved maximum document limit. - [Cohere Model Names Are Changing!](cohere-model-names-are-changing.md): We've updated our model names for simplicity and consistency, and old names will work for now. - [Multilingual Support for Co.classify](multilingual-support-for-coclassify.md): The co.classify endpoint now supports multilingual capabilities with the new multilingual-22-12 model. - [Command Model Nightly Available!](command-model-nightly-available.md): Get improved performance with our new nightly versions of Command models, now available in medium and x-large sizes. - [Command R+ is a scalable LLM for business](command-r-is-a-scalable-llm-for-business.md): Explore Command R+, Cohere's powerful language model, excelling in multi-step tool use and complex conversational AI ... - [Multilingual Text Model + Language Detection](multilingual-text-model-language-detection.md): Cohere's multilingual model now supports semantic search across 100 languages with a single index. - [Model Sizing Update + Improvements](model-sizing-update-improvements.md): We're updating our generative AI models to offer improved Medium and X-Large options. - [Current Model Upgrades + New Command Beta Model](current-model-upgrades-new-command-beta-model.md): Introducing new and improved Medium and XLarge models, plus a Command model for precise responses to commands. - [New Look For Cohere Documentation!](new-look-for-cohere-documentation.md): Explore our updated docs with interactive tutorials, improved info architecture, and a UI refresh for a streamlined e... - [Co.classify uses Representational model embeddings](coclassify-uses-representational-model-embeddings.md): Improve few-shot classification with Co.classify and embeddings from our Representational model. - [New Logit Bias experimental parameter](new-logit-bias-experimental-parameter.md): Take control of your generative models with the new logit_bias parameter to guide token generation. - [Pricing Update and New Dashboard UI](pricing-update-and-new-dashboard-ui.md): Unlock new features, including production keys, flat-rate pricing, improved UI, and enhanced team collaboration and m... - [Introducing Moderate Tool (Beta)!](introducing-moderate-tool-beta.md): Access cutting-edge natural language processing tools without the need for costly supercomputing power. - [The `model` Parameter Becomes Optional.](the-model-parameter-becomes-optional.md): Our APIs are now model-agnostic with default endpoint settings, offering greater flexibility and control for users. - [New & Improved Generation and Representation Models](new-improved-generation-and-representation-models.md): Enhance your text generation and representation with improved models, now offering better context support and optimal... - [New and Improved Extremely Large Model!](new-and-improved-extremely-large-model.md): We're thrilled to introduce our enhanced`xlarge`model, now with superior generation quality and speed. - [Updated Small, Medium, and Large Generation Models](updated-small-medium-and-large-generation-models.md): The latest updates improve model stability and fix a bug for more effective generation presence and frequency penalties. - [Introducing Classification Endpoint](introducing-classification-endpoint.md): Classify text with Cohere's new classification endpoint, powered by generation models, offering few-shot learning. - [Finetuning Available + Policy Updates](finetuning-available-policy-updates.md): Fine-tune models with your own data and leverage updated policies for powerful NLP solutions. - [New & Improved Generation Models](new-improved-generation-models.md): Try our new small, medium, and large generation models with improved performance from our high-quality dataset. - [Extremely Large (Beta) Release](extremely-large-beta-release.md): Take your NLP tasks further with our new top-tier model, Extremely Large (Beta), now available. - [Larger Cohere Representation Models](larger-cohere-representation-models.md): New Representation Model sizes and an increased token limit offer improved performance and flexibility. - [Cookbooks](cookbooks.md): Explore a range of AI guides and get started with Cohere's generative platform, ready-made and best-practice optimized. - [Building an LLM Agent with the Cohere API](building-an-llm-agent-with-the-cohere-api.md): This page how to use Cohere's API to build an LLM-based agent. - [Uncomment if you need to install the following packages](uncomment-if-you-need-to-install-the-following-packages.md) - [!pip install pandas](pip-install-pandas.md): import os - [load the cohere api key](load-the-cohere-api-key.md): os.environ["COHERE_API_KEY"] = getpass.getpass() - [Step 2: Define the Tool and the Agent \[#sec\_step2]](step-2-define-the-tool-and-the-agent-sec-step2.md): Here we create a tool which implements the deterministic function to extract alphanumeric strings - [Let's define the system instruction (preamble) for the Agent.](lets-define-the-system-instruction-preamble-for-the-agent.md) - [- the cases in which the Agent has to produce an output without using the tool](the-cases-in-which-the-agent-has-to-produce-an-output-without-using-the-tool.md) - [- some examples to clarify the task](some-examples-to-clarify-the-task.md): preamble = """You are an assistant that given a user's query about, generates a request an API. - [Define the prompt](define-the-prompt.md): prompt = ChatPromptTemplate.from_template("{input}") - [Define the agent](define-the-agent.md): llm = ChatCohere(model="command-a-03-2025", temperature=0) - [instantiate agent and agent executor](instantiate-agent-and-agent-executor.md): agent = create_cohere_react_agent( - [finally, let's write a function to convert the Agents output to a json](finally-lets-write-a-function-to-convert-the-agents-output-to-a-json.md): def convert_to_json(string: str) -> json: - [Step 3: Run the Agent \[#sec\_step3]](step-3-run-the-agent-sec-step3.md): Let's now test the Agent we just defined! - [let's have a look at the final output](lets-have-a-look-at-the-final-output.md): convert_to_json(response_1['output']) - [Conclusions \[#sec\_conclusion]](conclusions-sec-conclusion.md): In this notebook we showed how Agents can be used to solve a real-world use case, in which the goal is to create API ... - [Short-Term Memory Handling for Agents](short-term-memory-handling-for-agents.md): This page describes how to manage short-term memory in an agent built with Cohere models. - [Step 1: Setup the Prompt and the Agent \[#sec\_step1]](step-1-setup-the-prompt-and-the-agent-sec-step1.md) - [Uncomment if you need to install the following packages](uncomment-if-you-need-to-install-the-following-packages-2.md) - [!pip install pandas](pip-install-pandas-2.md): import os - [load the cohere api key](load-the-cohere-api-key-2.md): os.environ["COHERE_API_KEY"] = getpass.getpass() - [Load the data](load-the-data.md): revenue_table = pd.read_csv('revenue_table.csv') - [Define the prompt](define-the-prompt-2.md): prompt = ChatPromptTemplate.from_template("{input}") - [Define the tools](define-the-tools-2.md): python_repl = PythonREPL() - [Define the agent](define-the-agent-2.md): llm = ChatCohere(model="command-r", temperature=0) - [instantiate agent and agent executor](instantiate-agent-and-agent-executor-2.md): agent = create_cohere_react_agent( - [Step 2: Conversation without memory \[#sec\_step2]](step-2-conversation-without-memory-sec-step2.md) - [let's start the conversation with a question about the csv we have loaded](lets-start-the-conversation-with-a-question-about-the-csv-we-have-loaded.md): q1 = "read revenue_table.csv and show me the column names" - [nice! now let's ask a follow-up question](nice-now-lets-ask-a-follow-up-question.md): q2 = "plot revenue numbers" - [Step 3: Conversation with Memory using AI Messages \[#sec\_step3]](step-3-conversation-with-memory-using-ai-messages-sec-step3.md): Here we will populate the chat history only with the generations from the model. This is the current approach used, e... - [let's answer the followup question above with the new setup](lets-answer-the-followup-question-above-with-the-new-setup.md): a2_mem_ai = agent_executor.invoke({ - [Step 4: Conversation with Memory using AI Messages and Human Messages \[#sec\_step4]](step-4-conversation-with-memory-using-ai-messages-and-human-messages-sec-step4.md): a2_mem_ai_hum = agent_executor.invoke({ - [Step 5: Conversation with Memory using AI Messages, Human Messages and the Reasoning Chain \[#sec\_step5]](step-5-conversation-with-memory-using-ai-messages-human-messages-and-the-reasoni.md): Reasoning chains can be very long, especially in the cases that contain errors and the agent needs several attempts t... - [function to create augmented memory objects](function-to-create-augmented-memory-objects.md): def create_augmented_mem_objs(output_previous_turn: dict) -> str: - [Agentic Multi-Stage RAG with Cohere Tools API](agentic-multi-stage-rag-with-cohere-tools-api.md): This page describes how to build a powerful, multi-stage agent with the Cohere platform. - [versions](versions.md): print('cohere version:', cohere.__version__) - [comebine title and body](comebine-title-and-body.md): db["combined"] = "Title: " + db["title"] + "\n" + "Body: " + db["body"] - [generate embedding](generate-embedding.md): embeddings = co.embed( - [Agentic RAG for PDFs with mixed data](agentic-rag-for-pdfs-with-mixed-data.md): This page describes building a powerful, multi-step chatbot with Cohere's models. - [Reference Documents](reference-documents.md): We recommend the following notebook as a guide to [semi-structured RAG](https://github.com/langchain-ai/langchain/blo... - [there may be other dependencies that will need installation](there-may-be-other-dependencies-that-will-need-installation.md) - [! pip install --quiet langchain langchain_cohere langchain_experimental](pip-install-quiet-langchain-langchain-cohere-langchain-experimental.md) - [LLM](llm.md): import os - [Parsing \[#sec\_step1]](parsing-sec-step1.md): To improve RAG performance on PDFs with mixed types (text and tables), we investigated a number of parsing and chunki... - [Get elements](get-elements.md): raw_pdf_elements = partition_pdf( - [extract table and textual objects from parser](extract-table-and-textual-objects-from-parser.md): class Element(BaseModel): - [Categorize by type](categorize-by-type.md): categorized_elements = [] - [Tables](tables.md): table_elements = [e for e in categorized_elements if e.type == "table"] - [Text](text.md): text_elements = [e for e in categorized_elements if e.type == "text"] - [Vector Store Setup \[#sec\_step2]](vector-store-setup-sec-step2.md): There are many options for setting up a vector store. Here, we show how to do so using [Chroma](https://www.trychroma... - [generate table and text summaries](generate-table-and-text-summaries.md): prompt_text = """You are an assistant tasked with summarizing tables and text. \ - [The vectorstore to use to index the child chunks](the-vectorstore-to-use-to-index-the-child-chunks.md): vectorstore = Chroma(collection_name="summaries", embedding_function=CohereEmbeddings()) - [The storage layer for the parent documents](the-storage-layer-for-the-parent-documents.md): store = InMemoryStore() - [The retriever (empty to start)](the-retriever-empty-to-start.md): retriever = MultiVectorRetriever( - [Add texts](add-texts.md): doc_ids = [str(uuid.uuid4()) for _ in texts] - [Add tables](add-tables.md): table_ids = [str(uuid.uuid4()) for _ in tables] - [RAG Pipeline \[#sec\_step3]](rag-pipeline-sec-step3.md): With our database in place, we can run queries against it. The query process can be broken down into the following st... - [RAG Pipeline Class \[#sec\_step4]](rag-pipeline-class-sec-step4.md): Here, we connect all of the pieces discussed above into one class object, which is then used as a tool for a Cohere R... - [Cohere ReAct Agent with RAG Tool \[#sec\_step5]](cohere-react-agent-with-rag-tool-sec-step5.md): Finally, we build a simple agent that utilizes the RAG pipeline defined above. We do this by granting the agent acces... - [Conclusion](conclusion.md): As you can see, the RAG pipeline can be used as a tool for a Cohere ReAct agent. This allows the agent to access the ... - [Analysis of Form 10-K/10-Q Using Cohere and RAG](analysis-of-form-10-k10-q-using-cohere-and-rag.md): This page describes how to use Cohere's large language models to build an agent able to analyze financial forms like ... - [Due to compatibility issues, we need to do imports like this](due-to-compatibility-issues-we-need-to-do-imports-like-this.md): from llama_index.core.schema import TextNode - [Set up Cohere client](set-up-cohere-client.md): COHERE_API_KEY = getpass("Enter your Cohere API key: ") - [Instantiate a client to communicate with Cohere's API using our Python SDK](instantiate-a-client-to-communicate-with-coheres-api-using-our-python-sdk.md): co = cohere.Client(COHERE_API_KEY) - [Using langchain here since they have access to the Unstructured Data Loader powered by unstructured.io](using-langchain-here-since-they-have-access-to-the-unstructured-data-loader-powe.md): from langchain_community.document_loaders import UnstructuredURLLoader - [Load up Airbnb's 10-K from this past fiscal year (filed in 2024)](load-up-airbnbs-10-k-from-this-past-fiscal-year-filed-in-2024.md) - [Feel free to fill in some other EDGAR path](feel-free-to-fill-in-some-other-edgar-path.md): url = " - [Load the document(s) as simple text nodes, to be passed to the tokenization processor](load-the-documents-as-simple-text-nodes-to-be-passed-to-the-tokenization-process.md): nodes = [TextNode(text=document.page_content, id_=f"doc_{i}") for i, document in enumerate(documents)] - [TODO: replace with a HF implementation so this is much faster. We'll](todo-replace-with-a-hf-implementation-so-this-is-much-faster-well.md) - [presumably release it when we OS the model](presumably-release-it-when-we-os-the-model.md): tokenizer_fn = lambda x: tokenizer(x).input_ids if len(x) > 0 else [] - [Run the pipeline to transform the text](run-the-pipeline-to-transform-the-text.md): nodes = pipeline.run(nodes=nodes) - [Instantiate the embedding model](instantiate-the-embedding-model.md): embed_model = CohereEmbedding(cohere_api_key=COHERE_API_KEY) - [Global settings](global-settings.md): Settings.chunk_size = 512 - [Create the vector store](create-the-vector-store.md): index = VectorStoreIndex(nodes) - [Instantiate the reranker](instantiate-the-reranker.md): rerank = CohereRerank(api_key=COHERE_API_KEY, top_n=15) - [Function `retrieve` is ready, using both Cohere embeddings for similarity search as well as](function-retrieve-is-ready-using-both-cohere-embeddings-for-similarity-search-as.md): retrieve = lambda query: rerank.postprocess_nodes(retriever.retrieve(query), query_str=query) - [Get queries to run against our index from the model](get-queries-to-run-against-our-index-from-the-model.md): r = co.chat(PROMPT, model="command-r", search_queries_only=True) - [Convenience function for formatting documents](convenience-function-for-formatting-documents.md): def format_for_cohere_client(nodes_): - [Retrieve a set of chunks from the vector index and append them to the list of](retrieve-a-set-of-chunks-from-the-vector-index-and-append-them-to-the-list-of.md) - [documents that should be included in the final RAG step](documents-that-should-be-included-in-the-final-rag-step.md): for query in queries: - [One final dedpulication step in case multiple queries return the same chunk](one-final-dedpulication-step-in-case-multiple-queries-return-the-same-chunk.md): documents = [dict(t, id=f"doc_{i}") for i, t in enumerate({tuple(d.items()) for d in documents})] - [Make a request to the model](make-a-request-to-the-model.md): response = co.chat( - [Helper function for displaying response WITH citations](helper-function-for-displaying-response-with-citations.md): def insert_citations(text: str, citations: list[dict]): - [**Appendix**](appendix.md): This method will be required for any PDFs you have that need to be converted to text. - [pdf2image extracts as a list of PIL.Image objects](pdf2image-extracts-as-a-list-of-pilimage-objects.md) - [TODO: host this PDF somewhere](todo-host-this-pdf-somewhere.md): pages = convert_from_path("/content/uber_10k.pdf") - [We access the only page in this sample PDF by indexing at 0](we-access-the-only-page-in-this-sample-pdf-by-indexing-at-0.md): pages = [pytesseract.image_to_string(page) for page in pages] - [question](question.md): {question}""" - [Analyzing Hacker News with Cohere](analyzing-hacker-news-with-cohere.md): This page describes building a generative-AI powered tool to analyze headlines with Cohere. - [Article Recommender via Embedding & Classification](article-recommender-via-embedding-classification.md): This page describes how to build a generative-AI tool to recommend articles with Cohere. - [Multi-Step Tool Use with Cohere](multi-step-tool-use-with-cohere.md): This page describes how to create a multi-step, tool-using AI agent with Cohere's tool use functionality. - [Basic RAG: Retrieval-Augmented Generation with Cohere](basic-rag-retrieval-augmented-generation-with-cohere.md): This page describes how to work with Cohere's basic retrieval-augmented generation functionality. - [! pip install wikipedia -qq](pip-install-wikipedia-qq.md): import wikipedia - [let's get the wikipedia article about Dune Part Two](lets-get-the-wikipedia-article-about-dune-part-two.md): article = wikipedia.page('Dune Part Two') - [For chunking let's use langchain to help us split the text](for-chunking-lets-use-langchain-to-help-us-split-the-text.md): ! pip install -qU langchain-text-splitters -qq - [Because the texts being embedded are the chunks we are searching over, we set the input type as search_doc](because-the-texts-being-embedded-are-the-chunks-we-are-searching-over-we-set-the.md): model = "embed-v4.0" - [{ 0: array([...]), 1: array([...]), 2: array([...]), ..., 10: array([...]) }](0-array-1-array-2-array-10-array.md): query = "Name everyone involved in writing the script, directing, and producing 'Dune: Part Two'?" - [Note: the relevant passage in the wikipedia page we're looking for is:](note-the-relevant-passage-in-the-wikipedia-page-were-looking-for-is.md) - ["[...] Dune: Part Two was originally scheduled to be released on October 20, 2023, but was delayed to November 17, 2023, before moving forward two weeks to November 3, 2023, to adjust to changes in release schedules from other studios. It was later postponed by over four months to March 15, 2024, due to the 2023 Hollywood labor disputes. After the strikes were resolved, the film moved once more up two weeks to March 1, 2024. [...]"](dune-part-two-was-originally-scheduled-to-be-released-on-october-20-2023-but-was.md): Cohere embeddings are state-of-the-art. - [Because the text being embedded is the search query, we set the input type as search_query](because-the-text-being-embedded-is-the-search-query-we-set-the-input-type-as-sea.md): response = co.embed( - [Calculate similarity between the user question & each chunk](calculate-similarity-between-the-user-question-each-chunk.md): similarities = [cosine_similarity(query_embedding, chunk) for chunk in embeddings] - [Get indices of the top 10 most similar chunks](get-indices-of-the-top-10-most-similar-chunks.md): sorted_indices = np.argsort(similarities)[::-1] - [Keep only the top 10 indices](keep-only-the-top-10-indices.md): top_indices = sorted_indices[:10] - [Retrieve the top 10 most similar chunks](retrieve-the-top-10-most-similar-chunks.md): top_chunks_after_retrieval = [chunks[i] for i in top_indices] - [top_chunks_after_rerank = [result.document['text'] for result in response]](top-chunks-after-rerank-resultdocumenttext-for-result-in-response.md): top_chunks_after_rerank = [top_chunks_after_retrieval[result.index] for result in response.results] - [preamble containing instructions about the task and the desired style for the output.](preamble-containing-instructions-about-the-task-and-the-desired-style-for-the-ou.md): preamble = """ - [retrieved documents](retrieved-documents.md): documents = [ - [get model response](get-model-response.md): response = co.chat( - [Use the functions](use-the-functions.md): cited_text = insert_inline_citations(response.message.content[0].text, response.message.citations) - [Print the result with inline citations](print-the-result-with-inline-citations.md): print(cited_text) - [Print footnotes](print-footnotes.md): if response.message.citations: - [Basic Semantic Search with Cohere Models](basic-semantic-search-with-cohere-models.md): This page describes how to do basic semantic search with Cohere's models. - [Getting Started with Basic Tool Use](getting-started-with-basic-tool-use.md): This page describes how to work with Cohere's basic tool use functionality. - [Calendar Agent with Native Multi Step Tool](calendar-agent-with-native-multi-step-tool.md): This page describes how to use cohere Chat API with list_calendar_events and create_calendar_event tools to book appo... - [!pip install cohere==5.5.3](pip-install-cohere553.md) - [Instantiate the Cohere client](instantiate-the-cohere-client.md): import cohere - [Define the tools](define-the-tools-3.md): import json - [helper function for routing to the correct tool](helper-function-for-routing-to-the-correct-tool.md): def invoke_tool(tool_call: cohere.ToolCall): - [Check what tools the model wants to use and how to use them](check-what-tools-the-model-wants-to-use-and-how-to-use-them.md): res = co.chat( - [Effective Chunking Strategies for RAG](effective-chunking-strategies-for-rag.md): This page describes various chunking strategies you can use to get better RAG performance. - [Get all investement memos (19) in bvp repository](get-all-investement-memos-19-in-bvp-repository.md): url_path = ' - [Define the question](define-the-question.md): question = "Who mentions Jonathan Nolan?" - [Define the chunking function](define-the-chunking-function.md): def get_chunks(text, chunk_size, chunk_overlap): - [Creating a QA Bot From Technical Documentation](creating-a-qa-bot-from-technical-documentation.md): This page describes how to use Cohere to build a simple question-answering system. - [Financial CSV Agent with Native Multi-Step Cohere API](financial-csv-agent-with-native-multi-step-cohere-api.md): This page describes how to use Cohere's models and its native API to build an agent able to work with CSV data. - [Notebook Overview](notebook-overview.md): Tabular data reasoning continues to be an exciting application of Agents, particularly in the financial domain, where... - [Setup \[#setup]](setup-setup.md): import os - [Uncomment if you need to install the following packages](uncomment-if-you-need-to-install-the-following-packages-3.md) - [!pip install --quiet langchain langchain_experimental cohere --upgrade](pip-install-quiet-langchain-langchain-experimental-cohere-upgrade.md) - [versions](versions-2.md): print('cohere version:', cohere.__version__) - [Define Python Tool \[#define\_python\_tool]](define-python-tool-define-python-tool.md): Here we define the python tool using langchain's PythonREPL. We also define`functions_map`that will later be used b... - [Create Cohere Agent \[#create\_cohere\_agent]](create-cohere-agent-create-cohere-agent.md): As [Multi-Step Tool Use](https://docs.cohere.com/page/basic-multi-step) shows, you have a lot of flexiblity on how yo... - [test](test.md): output = cohere_agent("can you use python to answer 1 + 1", None, tools, verbose=True) - [QnA over Single Table \[#qna\_over\_single\_table]](qna-over-single-table-qna-over-single-table.md): In the example below, we show how the Python tool can be used to load a dataframe and extract information from it. To... - [QnA over Multiple Tables \[#qna\_over\_multiple\_tables]](qna-over-multiple-tables-qna-over-multiple-tables.md): We now make the task for the Agent more complicated by asking a question that can be only answered by retrieving rele... - [get the largest stockholders equity](get-the-largest-stockholders-equity.md): x = balance_sheet['StockholdersEquity'].astype(float).max() - [get the smallest revenue](get-the-smallest-revenue.md): y = income_statement['RevenueFromContractWithCustomerExcludingAssessedTax'].astype(float).min() - [compute the ratio](compute-the-ratio.md): ratio = x/y - [Error Resilience \[#error\_resilience]](error-resilience-error-resilience.md): In the previous example over single table, the model successfully answered your questions. However, the model may not... - [Financial CSV Agent with Langchain](financial-csv-agent-with-langchain.md): This page describes how to use Cohere's models to build an agent able to work with CSV data. - [Notebook Overview](notebook-overview-2.md): Tabular data reasoning continues to be an exciting application of Agents, particularly in the financial domain, where... - [Setup \[#sec\_step0]](setup-sec-step0.md): from langchain_core.pydantic_v1 import BaseModel, Field - [Uncomment if you need to install the following packages](uncomment-if-you-need-to-install-the-following-packages-4.md) - [Introduction \[#sec\_step1]](introduction-sec-step1.md): The aim of this notebook is to showcase how Cohere Langchain Agents can be used to answer questions over tabular data. - [QnA over Single Table{" "} \[#sec\_step2]](qna-over-single-table-sec-step2.md): In the example below, we show how the python tool can be used to load a dataframe and extract information from it. To... - [instantiate the Cohere llm](instantiate-the-cohere-llm.md): llm = ChatCohere(model="command-r", temperature=0.1,cohere_api_key="",verbose=True) - [create the python tool](create-the-python-tool.md): python_repl = PythonREPL() - [define the prompt template](define-the-prompt-template.md): prompt = ChatPromptTemplate.from_template("{input}") - [instantiate the ReAct agent](instantiate-the-react-agent.md): agent = create_cohere_react_agent( - [finally, define the preamble](finally-define-the-preamble.md): preamble = """ - [call the PythonAstREPLTool in order to pass tables to the tool](call-the-pythonastrepltool-in-order-to-pass-tables-to-the-tool.md): df_locals = {'df':pd.read_csv('income_statement.csv')} - [QnA over Multiple Tables \[#sec\_step3]](qna-over-multiple-tables-sec-step3.md): We now make the task for the Agent more complicated, by asking it questions whose answer can be computed only by retr... - [define the Agent](define-the-agent-3.md): python_repl = PythonREPL() - [get the largest stockholders equity](get-the-largest-stockholders-equity-2.md): x = balance_sheet['StockholdersEquity'].astype(float).max() - [get the smallest revenue](get-the-smallest-revenue-2.md): y = income_statement['RevenueFromContractWithCustomerExcludingAssessedTax'].astype(float).min() - [compute the ratio](compute-the-ratio-2.md): ratio = x/y - [Migrating away from create_csv_agent in langchain-cohere](migrating-away-from-create-csv-agent-in-langchain-cohere.md): This page contains a tutorial on how to build a CSV agent without the deprecated`create_csv_agent`abstraction in la... - [How to build a CSV Agent without using deprecated `create_csv_agent` - langchain-cohere](how-to-build-a-csv-agent-without-using-deprecated-create-csv-agent-langchain-coh.md): Starting from version 0.3.5 of the langchain-cohere package, the`create_csv_agent`abstraction has been deprecated. - [Import packages](import-packages.md): from datetime import datetime - [Replace this cell with your actual cohere api key](replace-this-cell-with-your-actual-cohere-api-key.md): os.env["COHERE_API_KEY"] = "cohere_api_key" - [Define prompts that we want to use in the csv agent](define-prompts-that-we-want-to-use-in-the-csv-agent.md): FUNCTIONS_WITH_DF = """ - [Define tools that we want the csv agent to have access to](define-tools-that-we-want-the-csv-agent-to-have-access-to.md): def get_file_peek_tool() -> Tool: - [Build the agent abstraction itself](build-the-agent-abstraction-itself.md): def create_csv_agent( - [Using the CSV agent](using-the-csv-agent.md): Let's create a dummy CSV file for demo - [Data to be written to the CSV file](data-to-be-written-to-the-csv-file.md): data = [ - [Try out an example](try-out-an-example.md): llm = ChatCohere(model="command-a-03-2025", temperature=0) - [A Data Analyst Agent Built with Cohere and Langchain](a-data-analyst-agent-built-with-cohere-and-langchain.md): This page describes how to build a data-analysis system out of Cohere's models. - [Advanced Document Parsing For Enterprises](advanced-document-parsing-for-enterprises.md): This page describes how to use Cohere's models to build a document-parsing agent. - [credentials_file = "populate if you are running in a non Vertex AI environment."](credentials-file-populate-if-you-are-running-in-a-non-vertex-ai-environment.md): gcs_input_prefix = "" - [versioned_parsed_documents = batch_process_documents(](versioned-parsed-documents-batch-process-documents.md) - [)](untitled.md): """ - [Assemble versioned documents together ({"doc_name": [(0, doc_content_0), (1, doc_content_1), ...]}).](assemble-versioned-documents-together-doc-name-0-doc-content-0-1-doc-content-1.md): for filename, doc_content in versioned_parsed_documents: - [Sort documents by version and join the content together.](sort-documents-by-version-and-join-the-content-together.md): for filename, docs in combined_versioned_parsed_documents.items(): - [Store parsed documents in local storage.](store-parsed-documents-in-local-storage.md): for filename, doc_content in parsed_documents: - [source: https://github.com/awsdocs/aws-doc-sdk-examples/tree/main/python/example_code/textract](source-httpsgithubcomawsdocsaws-doc-sdk-examplestreemainpythonexample-codetextra.md) - [Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.](copyright-amazoncom-inc-or-its-affiliates-all-rights-reserved.md) - [SPDX-License-Identifier: Apache-2.0](spdx-license-identifier-apache-20.md): """ - [snippet-start:[python.example_code.textract.TextractWrapper]](snippet-startpythonexample-codetextracttextractwrapper.md): class TextractWrapper: - [snippet-end:[python.example_code.textract.GetDocumentAnalysis]](snippet-endpythonexample-codetextractgetdocumentanalysis.md): Next, we set up Textract and S3, and provide this to an instance of`TextractWrapper`. - [kick off a text detection job. This returns a job ID.](kick-off-a-text-detection-job-this-returns-a-job-id.md): job_id = textractWrapper.start_detection_job(bucket_name=bucket_name, document_file_name=file_name, - [Text mode](text-mode.md): text_parser = LlamaParse( - [Markdown mode](markdown-mode.md): markdown_parser = LlamaParse( - [Text parsing](text-parsing.md): filename = "llamaparse-text-parsed-{}.txt".format(source_filename) - [Markdown parsing](markdown-parsing.md): filename = "llamaparse-markdown-parsed-fda-approved-drug.txt" - [pdf2image extracts as a list of PIL.Image objects](pdf2image-extracts-as-a-list-of-pilimage-objects-2.md): pages = convert_from_path(filename) - [we look at the first page as a sanity check:](we-look-at-the-first-page-as-a-sanity-check.md): plt.imshow(pages[0]) - [prompt = "What is the recommended dosage of Iwilfin on body surface area between 0.5 m2 and 0.75 m2?"](prompt-what-is-the-recommended-dosage-of-iwilfin-on-body-surface-area-between-05.md) - [prompt = "I need a succinct summary of the compound name, indication, route of administration, and mechanism of action of Iwilfin."](prompt-i-need-a-succinct-summary-of-the-compound-name-indication-route-of-admini.md): """ - [source = "pytesseract"](source-pytesseract.md): In order to set up our RAG implementation, we need to separate the parsed text into chunks and load the chunks to an ... - [Chunk doc content](chunk-doc-content.md): text_splitter = RecursiveCharacterTextSplitter( - [Split the text into chunks with some overlap](split-the-text-into-chunks-with-some-overlap.md): chunks_ = text_splitter.create_documents([doc_content]) - [End-to-end RAG using Elasticsearch and Cohere](end-to-end-rag-using-elasticsearch-and-cohere.md): This page contains a basic tutorial on how to get Cohere and ElasticSearch to work well together. - [Serverless Semantic Search with Cohere and Pinecone](serverless-semantic-search-with-cohere-and-pinecone.md): This page contains a basic tutorial on how to get Cohere and the Pinecone vector database to work well together. - [Semantic Search with Cohere Embed Jobs](semantic-search-with-cohere-embed-jobs.md): This page contains a basic tutorial on how to use Cohere's Embed Jobs functionality. - [Fueling Generative Content with Keyword Research](fueling-generative-content-with-keyword-research.md): This page contains a basic workflow for using Cohere's models to come up with keyword content ideas. - [Grounded Summarization Using Command R](grounded-summarization-using-command-r.md): This page contains a basic tutorial on how to do grounded summarization with Cohere's models. - [3. Introduce citations to the summary for grounding \[#introduce-citations-to-the-summary-for-grounding]](3-introduce-citations-to-the-summary-for-grounding-introduce-citations-to-the-su.md): When summarizing long documents, introducing citations is one simple method for checking the factuality of the summar... - [4. Reduce the cost of summarization calls \[#reduce-the-cost-of-summarization-calls]](4-reduce-the-cost-of-summarization-calls-reduce-the-cost-of-summarization-calls.md): Even though Command-R is an efficient, light-weight model, for some applications we may accept trading off some summa... - [Hello World! Explore Language AI with Cohere](hello-world-explore-language-ai-with-cohere.md): This page contains a breakdown of some of what can be achieved with Cohere's LLM platform. - [Long-Form Text Strategies with Cohere](long-form-text-strategies-with-cohere.md): This discusses ways of getting Cohere's LLM platform to perform well in generating long-form text. - [Set up Cohere client](set-up-cohere-client-2.md): co_model = 'command-a-03-2025' - [Download the PDF file from the URL](download-the-pdf-file-from-the-url.md): pdf_url = ' - [Load the PDF file and extract its text content](load-the-pdf-file-and-extract-its-text-content.md): long_text = load_long_pdf(save_path) - [Print the length of the document](print-the-length-of-the-document.md): print("Document length - #tokens:", len(co.tokenize(text=long_text, model=co_model).tokens)) - [Example summary prompt.](example-summary-prompt.md): prompt_template = """ - [print(generate_response(message=prompt))](printgenerate-responsemessageprompt.md): Therefore, in the following sections, we will explore some techniques to address this limitation. - [The new Cohere model has a context limit of 128k tokens. However, for the purpose of this exercise, we will assume a smaller context window.](the-new-cohere-model-has-a-context-limit-of-128k-tokens-however-for-the-purpose-.md) - [Employing a smaller context window also has the additional benefit of reducing the cost per request, especially if billed by the number of tokens.](employing-a-smaller-context-window-also-has-the-additional-benefit-of-reducing-t.md): MAX_TOKENS = 40000 - [Example prompt](example-prompt.md): prompt_template = """ - [Example summary prompt.](example-summary-prompt-2.md): prompt_template = """ - [Migrating Monolithic Prompts to Command A with RAG](migrating-monolithic-prompts-to-command-a-with-rag.md): This page contains a discussion of how to automatically migrating monolothic prompts. - [Multilingual Search with Cohere and Langchain](multilingual-search-with-cohere-and-langchain.md): This page contains a basic tutorial on how to do search across different languages with Cohere's LLM platform. - [PDF Extractor with Native Multi Step Tool Use](pdf-extractor-with-native-multi-step-tool-use.md): This page describes how to create an AI agent able to extract information from PDFs. - [!pip install cohere unstructured](pip-install-cohere-unstructured.md) - [versions](versions-3.md): print('cohere version:', cohere.__version__) - [Pondr, Fostering Connection through Good Conversation](pondr-fostering-connection-through-good-conversation.md): This page contains a basic tutorial on how tplay an AI-powered version of the icebreaking game 'Pondr'. - [Deep Dive Into Evaluating RAG Outputs](deep-dive-into-evaluating-rag-outputs.md): This page contains information on evaluating the output of RAG systems. - [Table of content](table-of-content.md): 1. Getting started - [required imports](required-imports.md): from getpass import getpass - [Get keys](get-keys.md): openai_api_key = getpass("Enter your OpenAI API Key: ") - [uncomment if you want to use mistral](uncomment-if-you-want-to-use-mistral.md) - [Define the model you want to use - you can replace gpt-4 with any other gpt version](define-the-model-you-want-to-use-you-can-replace-gpt-4-with-any-other-gpt-versio.md): model = "gpt-4" - [uncomment if you want to use mistral](uncomment-if-you-want-to-use-mistral-2.md): if model == "gpt-4": - [let's define a function to get the model's response for a given input](lets-define-a-function-to-get-the-models-response-for-a-given-input.md): def get_response(model, client, prompt): - [load the DocugamiKgRagSec10Q dataset](load-the-docugamikgragsec10q-dataset.md): if os.path.exists("./data/source_files") and os.path.exists("./data/rag_dataset.json"): - [select the index of a single datapoint - the first one in the dataset](select-the-index-of-a-single-datapoint-the-first-one-in-the-dataset.md): idx = 0 - [and the golden docs](and-the-golden-docs.md): golden_docs = rag_dataset[idx].reference_answer.split('SOURCE(S): ')[1].split(', ') - [let's assume we have the following set of retrieved docs](lets-assume-we-have-the-following-set-of-retrieved-docs.md): retrieved_docs = ['2022 Q3 AAPL.pdf', '2023 Q1 MSFT.pdf', '2023 Q1 AAPL.pdf'] - [we can now instantiate the evaluator](we-can-now-instantiate-the-evaluator.md): evaluate_retrieval = RetrievalEvaluator() - [and run the evaluation](and-run-the-evaluation.md): evaluate_retrieval.run_evals(retrieved_docs,golden_docs) - [first, let's define a function which extracts the claims from a response](first-lets-define-a-function-which-extracts-the-claims-from-a-response.md): def extract_claims(query, response, model, client): - [now, let's consider this answer, which we previously generated with command-r](now-lets-consider-this-answer-which-we-previously-generated-with-command-r.md): response = "Apple's total net sales experienced a decline over the last year. The three-month period ended July 1, 20... - [let's extract the claims](lets-extract-the-claims.md): claims = extract_claims(query, response, model, client) - [and see what the model returns](and-see-what-the-model-returns.md): print(f"List of claims extracted from the model's response:\n\n{claims}") - [Let's create a function that checks each claim against a reference text,](lets-create-a-function-that-checks-each-claim-against-a-reference-text.md) - [which here we will call "context". As you will see, we will use different contexts,](which-here-we-will-call-context-as-you-will-see-we-will-use-different-contexts.md) - [depending on the metric we want to compute.](depending-on-the-metric-we-want-to-compute.md): def assess_claims(query, claims, context, model, client): - [Let's start with Faithfulness: in this case, we want to assess the claims](lets-start-with-faithfulness-in-this-case-we-want-to-assess-the-claims.md) - [in the response against the retrieved documents (i.e., context = retrieved documents)](in-the-response-against-the-retrieved-documents-ie-context-retrieved-documents.md) - [for the sake of clarity, we report the actual text of the retrieved documents](for-the-sake-of-clarity-we-report-the-actual-text-of-the-retrieved-documents.md): retrieved_documents = ['Products and Services Performance\nThe following table shows net sales by category for the th... - [get the Faithfulness assessment for each claim](get-the-faithfulness-assessment-for-each-claim.md): assessed_claims_faithfulness = assess_claims(query=query, - [given the list of claims and their label, compute the final score](given-the-list-of-claims-and-their-label-compute-the-final-score.md) - [as the proportion of correct claims over the full list of claims](as-the-proportion-of-correct-claims-over-the-full-list-of-claims.md): def get_final_score(claims_list): - [let's mess up the century, changing 2022 to 1922](lets-mess-up-the-century-changing-2022-to-1922.md): modified_response = response.replace('2022', '1922') - [extract the claims from the modified response](extract-the-claims-from-the-modified-response.md): modified_claims = extract_claims(query, modified_response, model, client) - [and get assess the modified claims](and-get-assess-the-modified-claims.md): assessed_modified_claims = assess_claims(query=query, - [let's get the gold answer from the dataset](lets-get-the-gold-answer-from-the-dataset.md): golden_answer = rag_dataset[idx].reference_answer - [and check the claims in the response against the gold.](and-check-the-claims-in-the-response-against-the-gold.md) - [note that assess_claims takes exactly the same args as with Faithfulness](note-that-assess-claims-takes-exactly-the-same-args-as-with-faithfulness.md) - [except for the context, that now is the golden_answer](except-for-the-context-that-now-is-the-golden-answer.md): assessed_claims_correctness = assess_claims(query=query, - [we can now compute the final Correctness score](we-can-now-compute-the-final-correctness-score.md): score_correctness = get_final_score(assessed_claims_correctness) - [let's extract the golden claims](lets-extract-the-golden-claims.md): gold_claims = extract_claims(query, golden_answer, model, client) - [note that in, this case, the context is the model's response](note-that-in-this-case-the-context-is-the-models-response.md): assessed_claims_coverage = assess_claims(query=query, - [we compute the final Coverage score](we-compute-the-final-coverage-score.md): score_coverage = get_final_score(assessed_claims_coverage) - [RAG With Chat Embed and Rerank via Pinecone](rag-with-chat-embed-and-rerank-via-pinecone.md): This page contains a basic tutorial on how to build a RAG-powered chatbot. - [Learn How Cohere's Rerank Models Work](learn-how-coheres-rerank-models-work.md): This page contains a basic tutorial on how Cohere's ReRank models work and how to use them. - [Build a SQL Agent with Cohere's LLM Platform](build-a-sql-agent-with-coheres-llm-platform.md): This page contains a tutorial on how to build a SQL agent with Cohere's LLM platform. - [Toolkit Setup \[#sec\_step0]](toolkit-setup-sec-step0.md): from langchain.agents import AgentExecutor - [Uncomment if you need to install the following packages](uncomment-if-you-need-to-install-the-following-packages-5.md): Langchain already has a SQLDBToolkit that consists of 4 tools to handle SQL query generation, execution and validatio... - [load the cohere api key](load-the-cohere-api-key-3.md): os.environ["COHERE_API_KEY"] = "" - [SQL Agent \[#sec\_step1]](sql-agent-sec-step1.md): We follow the general cohere react agent setup in Langchain to build our SQL agent. - [define the prompt template](define-the-prompt-template-2.md): prompt = ChatPromptTemplate.from_template("{input}") - [instantiate the ReAct agent](instantiate-the-react-agent-2.md): agent = create_cohere_react_agent( - [SQL Agent with context \[#sec\_step2]](sql-agent-with-context-sec-step2.md): Generally, passing in additional context to the system instruction (preamble) can help reduce the initial failures. T... - [Evaluating Text Summarization Models](evaluating-text-summarization-models.md): This page discusses how to evaluate a model's text summarization. - [Get Started \[#start]](get-started-start.md): You'll need a Cohere API key to run this notebook. If you don't have a key, head to [ - [Construct the evaluation dataset \[#dataset]](construct-the-evaluation-dataset-dataset.md): We are interested in evaluating summarization in real-world, enterprise use cases, which typically have two distingui... - [Build the evaluation framework \[#eval-framework]](build-the-evaluation-framework-eval-framework.md): We now setup the tools we will use for evaluation. - [Run evaluations \[#run-evals]](run-evaluations-run-evals.md): Now that we have our evaluation dataset and defined our evaluation functions, let's run evaluations! - [Text Classification Using Embeddings](text-classification-using-embeddings.md): This page discusses the creation of a text classification model using word vector embeddings. - [Topic Modeling System for AI Papers](topic-modeling-system-for-ai-papers.md): This page discusses how to create a topic-modeling system for papers focused on AI papers. - [Reduce embeddings to 2 principal components to aid visualization](reduce-embeddings-to-2-principal-components-to-aid-visualization.md) - [Function to return the principal components](function-to-return-the-principal-components.md): def get_pc(arr,n): - [Function to generate the 2D plot](function-to-generate-the-2d-plot.md): def generate_chart(df,xcol,ycol,lbl='off',color='basic',title='', cluster_names=None): - [Add new query](add-new-query.md): new_query = "Anything on AI personalities?" - [Get embeddings of the new query](get-embeddings-of-the-new-query.md): new_query_embeds = get_embeddings(new_query) - [Get the similarity between the search query and existing queries](get-the-similarity-between-the-search-query-and-existing-queries.md): similarity = get_similarity(new_query_embeds, embeds) - [View the top 5 articles](view-the-top-5-articles.md): print('Query:') - [Wikipedia Semantic Search with Cohere + Weaviate](wikipedia-semantic-search-with-cohere-weaviate.md): This page contains a description of building a Wikipedia-focused search engine with Cohere's LLM platform and the Wea... - [Wikipedia Semantic Search with Cohere Embedding Archives](wikipedia-semantic-search-with-cohere-embedding-archives.md): This page contains a description of building a Wikipedia-focused semantic search engine with Cohere's LLM platform an... - [Build Chatbots with MongoDB and Cohere](build-chatbots-with-mongodb-and-cohere.md): This page describes how to build a chatbot that provides actionable insights on technology company market reports. - [Make sure you have an Hugging Face token(HF_TOKEN) in your development environemnt before running the code below](make-sure-you-have-an-hugging-face-tokenhf-token-in-your-development-environemnt.md) - [How to get a token: https://huggingface.co/docs/hub/en/security-tokens](how-to-get-a-token-httpshuggingfacecodocshubensecurity-tokens.md) - [https://huggingface.co/datasets/MongoDB/fake_tech_companies_market_reports](httpshuggingfacecodatasetsmongodbfake-tech-companies-market-reports.md): dataset = load_dataset( - [Convert the dataset to a pandas dataframe](convert-the-dataset-to-a-pandas-dataframe.md): dataset_df = pd.DataFrame(dataset_df) - [Data Preparation](data-preparation.md): def combine_attributes(row): - [Add the new column 'combined_attributes'](add-the-new-column-combined-attributes.md): dataset_df["combined_attributes"] = dataset_df.apply( - [Display the first few rows of the updated dataframe](display-the-first-few-rows-of-the-updated-dataframe.md): dataset_df[["company", "ticker", "combined_attributes"]].head() - [Apply the embedding function with a progress bar](apply-the-embedding-function-with-a-progress-bar.md): tqdm.pandas(desc="Generating embeddings") - [Delete any existing records in the collection](delete-any-existing-records-in-the-collection.md): collection.delete_many({}) - [Generating response with Cohere Command R](generating-response-with-cohere-command-r.md): response = co.chat( - [Initialize CohereChat](initialize-coherechat.md): chat = CohereChat( - [Send a message](send-a-message.md): response = chat.send_message( - [Show chat history](show-chat-history.md): chat.show_history() - [Finetuning on Cohere's Platform](finetuning-on-coheres-platform.md): An example of finetuning using Cohere's platform and a financial dataset. - [! pip install cohere](pip-install-cohere-6.md): import os - [fill in your Cohere API key here](fill-in-your-cohere-api-key-here.md): os.environ["COHERE_API_KEY"] = "" - [instantiate the Cohere client](instantiate-the-cohere-client-2.md): co = cohere.ClientV2(os.environ["COHERE_API_KEY"]) - [Deploy your finetuned model on AWS Marketplace](deploy-your-finetuned-model-on-aws-marketplace.md): Learn how to deploy your finetuned model on AWS Marketplace. - [Change "" to your own AWS profile name](change-aws-profile-to-your-own-aws-profile-name-2.md): os.environ["AWS_PROFILE"] = "" - [Get the arn of the bring your own finetuning algorithm by region](get-the-arn-of-the-bring-your-own-finetuning-algorithm-by-region-2.md): cohere_package = ( - [The local directory of your adapter weights. No need to specify this, if you bring your own merged weights](the-local-directory-of-your-adapter-weights-no-need-to-specify-this-if-you-bring-2.md): adapter_weights_dir = "" - [The local directory you want to save the merged weights. Or the local directory of your own merged weights, if you bring your own merged weights](the-local-directory-you-want-to-save-the-merged-weights-or-the-local-directory-o-2.md): merged_weights_dir = "" - [The S3 directory you want to save the merged weights](the-s3-directory-you-want-to-save-the-merged-weights-2.md): s3_checkpoint_dir = "" - [The S3 directory you want to save the exported TensorRT-LLM engine. Make sure you do not reuse the same S3 directory across multiple runs](the-s3-directory-you-want-to-save-the-exported-tensorrt-llm-engine-make-sure-you-2.md): s3_output_dir = "" - [The name of the export](the-name-of-the-export-2.md): export_name = "" - [The name of the SageMaker endpoint](the-name-of-the-sagemaker-endpoint-2.md): endpoint_name = "" - [The instance type for export and inference. Now "ml.p4de.24xlarge" and "ml.p5.48xlarge" are supported](the-instance-type-for-export-and-inference-now-mlp4de24xlarge-and-mlp548xlarge-a-2.md): instance_type = "" - [Get the merged model from adapter weights](get-the-merged-model-from-adapter-weights-2.md): merged_model = load_and_merge_model( - [Save the merged weights to your local directory](save-the-merged-weights-to-your-local-directory-2.md): save_hf_model(merged_weights_dir, merged_model) - [If the endpoint is already deployed, you can directly connect to it](if-the-endpoint-is-already-deployed-you-can-directly-connect-to-it-2.md): co.sagemaker_finetuning.connect_to_endpoint( - [Finetuning Cohere Models on AWS Sagemaker](finetuning-cohere-models-on-aws-sagemaker.md): Learn how to finetune one of Cohere's models on AWS Sagemaker. - [cohere_package = "cohere-command-r-ft-v-0-1-2-bae2282f0f4a30bca8bc6fea9efeb7ca"](cohere-package-cohere-command-r-ft-v-0-1-2-bae2282f0f4a30bca8bc6fea9efeb7ca.md) - [Mapping for algorithms](mapping-for-algorithms.md): algorithm_map = { - [You can download following example datasets from https://github.com/cohere-ai/cohere-developer-experience/tree/main/notebooks/data and upload them](you-can-download-following-example-datasets-from-httpsgithubcomcohere-aicohere-d.md) - [to the root of this juyter notebook](to-the-root-of-this-juyter-notebook.md): train_dataset = S3Uploader.upload( - [optional eval dataset](optional-eval-dataset.md): eval_dataset = S3Uploader.upload( - [DO NOT add a trailing slash at the end](do-not-add-a-trailing-slash-at-the-end.md): s3_models_dir = f"s3://..." - [Example of how to pass hyperparameters to the fine-tuning job](example-of-how-to-pass-hyperparameters-to-the-fine-tuning-job.md): train_parameters = { - [If the endpoint is already created, you just need to connect to it](if-the-endpoint-is-already-created-you-just-need-to-connect-to-it.md): co.connect_to_endpoint(endpoint_name=endpoint_name) - [SQL Agent with Cohere and LangChain (i-5O Case Study)](sql-agent-with-cohere-and-langchain-i-5o-case-study.md): This page contains a tutorial on how to build a SQL agent with Cohere and LangChain in the manufacturing industry. - [Create the engine](create-the-engine.md): engine = get_engine_for_manufacturing_db() - [Create the SQLDatabase instance](create-the-sqldatabase-instance.md): db = SQLDatabase(engine) - [Now you can use this db instance with your LangChain tools and agents](now-you-can-use-this-db-instance-with-your-langchain-tools-and-agents.md) - [Test the connection](test-the-connection.md): db.run("SELECT * FROM status LIMIT 5;") - [Test the connection](test-the-connection-2.md): db.run("SELECT * FROM product_tracking LIMIT 5;") - [Example formatted prompt](example-formatted-prompt.md): prompt_val = full_prompt.invoke( - [%%time](time.md): output=agent.invoke({ - [Answer: stn2, stn3 and stn5 had some downtime in the month of May 2024.](answer-stn2-stn3-and-stn5-had-some-downtime-in-the-month-of-may-2024.md): > Entering new Cohere SQL Agent Executor chain... - [Answer: 39.17 minutes](answer-3917-minutes.md): > Entering new Cohere SQL Agent Executor chain... - [Answer: stn4 - 251 minutes](answer-stn4-251-minutes.md): > Entering new Cohere SQL Agent Executor chain... - [Answer: stn2, with duration of 35 mins.](answer-stn2-with-duration-of-35-mins.md): > Entering new Cohere SQL Agent Executor chain... - [Answer: 21:52:00](answer-215200.md): > Entering new Cohere SQL Agent Executor chain... - [Introduction to Aya Vision](introduction-to-aya-vision.md): In this notebook, we will explore the capabilities of Aya Vision, which can take text and image inputs to generates t... - [Define the model](define-the-model.md): model="c4ai-aya-vision-32b" - [Retrieval evaluation using LLM-as-a-judge via Pydantic AI](retrieval-evaluation-using-llm-as-a-judge-via-pydantic-ai.md): This page contains a tutorial on how to evaluate retrieval systems using LLMs as judges via Pydantic AI. - [Generate 10 questions about geography to test the Wikipedia search](generate-10-questions-about-geography-to-test-the-wikipedia-search.md): geography_questions = [ - [Run search_wikipedia for each question](run-search-wikipedia-for-each-question.md): results = [] - [Rerank the search results for each question](rerank-the-search-results-for-each-question.md): top_n = 3 - [Print a sample of the reranked results](print-a-sample-of-the-reranked-results.md): print(f"Original question: {results_reranked_top_n[0]['question']}") - [Print a sample of the top_n results (without reranking)](print-a-sample-of-the-top-n-results-without-reranking.md): print(f"Original question: {results_top_n[0]['question']}") - [System prompt for the AI evaluator](system-prompt-for-the-ai-evaluator.md): SYSTEM_PROMPT = """ - [Prompt template for each evaluation](prompt-template-for-each-evaluation.md): PROMPT_TEMPLATE = """ - [Define the search engines](define-the-search-engines.md): engine_a = results_reranked_top_n - [Define the models to use as judges](define-the-models-to-use-as-judges.md): models = [ - [Get evaluation results](get-evaluation-results.md): results_df = evaluate_search_results(engine_a, engine_b, models) - [Calculate overall statistics](calculate-overall-statistics.md): winner_counts = Counter(results_df["winner"]) - [Display summary of results](display-summary-of-results.md): print("\nPercentage of questions won by each engine:") - [Save to CSV](save-to-csv.md): results_csv = results_df.to_csv("search_results_evaluation.csv", index=False) - [Document Translation with Command A Translate](document-translation-with-command-a-translate.md): This page describes how to use Command A Translate for automated translation across 23 languages with industry-leadin... - [1. Set up your Cohere client, translation prompt and maximum words per chunk](1-set-up-your-cohere-client-translation-prompt-and-maximum-words-per-chunk.md): import cohere - [2. Your source text](2-your-source-text.md): text = ( - [3. Define the chunk_split function (from earlier in your notebook)](3-define-the-chunk-split-function-from-earlier-in-your-notebook.md): def chunk_split(text, max_words, threshold=0.8): - [4. Split the text into chunks using chunk_split](4-split-the-text-into-chunks-using-chunk-split.md): chunks = chunk_split(text, max_words=max_words) - [5. Translate each chunk and collect results](5-translate-each-chunk-and-collect-results.md): translated_chunks = [] - [6. Merge the translated chunks back together](6-merge-the-translated-chunks-back-together.md): translated_text = " ".join(translated_chunks) - [7. Output the final translation](7-output-the-final-translation.md): print(translated_text)