-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add quickstarts - v1 and placeholder v2 * add quickstarts v2 API * misc changes * update quickstarts - pre snippets * update quickstarts and other docs * update quickstart descriptions * update quickstart snippets * update installation page * remove unneeded pages * update yml * update description * update some text --------- Co-authored-by: billytrend-cohere <144115527+billytrend-cohere@users.noreply.github.com>
- Loading branch information
1 parent
ced2d64
commit 540ebad
Showing
16 changed files
with
3,033 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
title: Installation | ||
slug: /docs/get-started-installation | ||
|
||
description: "A guide for installing the Cohere SDK, supported in 4 different languages – Python, TypeScript, Java, and Go." | ||
image: "../../assets/images/f1cc130-cohere_meta_image.jpg" | ||
keywords: "Cohere, Cohere SDK, API v1" | ||
--- | ||
|
||
## Platform options | ||
|
||
To be able to use Cohere’s models, first choose the platform where you want to access the model from. Cohere's models are available on the following platforms: | ||
|
||
| Platform | Description | Setup Guide | | ||
|-----------------|-----------------------------------------------------------------------------|----------------------------------------------------------------------------| | ||
| Cohere Platform | The fastest way to start using Cohere’s models. Hosted on Cohere infrastructure and available on our public SaaS platform. | [Sign up](https://dashboard.cohere.com/welcome/register) and get an [API key](https://dashboard.cohere.com/api-keys) (trial key available) | | ||
| Private Deployments | For enterprises looking to deploy the Cohere stack privately on the cloud or on-prem. | [Setup guide](https://docs.cohere.com/docs/single-container-on-private-clouds) | | ||
| Cloud deployments | Managed services from cloud providers that enable access to Cohere's models. | • [Amazon Bedrock](https://docs.cohere.com/docs/amazon-bedrock#prerequisites)<br/>• [Amazon SageMaker](https://docs.cohere.com/docs/amazon-sagemaker-setup-guide#prerequisites)<br/>• [Azure AI Foundry](https://docs.cohere.com/docs/cohere-on-microsoft-azure#prerequisites)<br/>• [Oracle OCI](https://docs.cohere.com/docs/oracle-cloud-infrastructure-oci) | | ||
## Model usage | ||
|
||
You can then use the models via these options: | ||
|
||
- [SDK](https://docs.cohere.com/v1/reference/about#sdks). We support the following SDKs: | ||
- [Python](https://github.com/cohere-ai/cohere-python) | ||
- [TypeScript](https://github.com/cohere-ai/cohere-typescript) | ||
- [Java](https://github.com/cohere-ai/cohere-java) | ||
- [Go](https://github.com/cohere-ai/cohere-go) | ||
- [CLI tool](https://docs.cohere.com/v1/reference/command) | ||
- [Playground](https://docs.cohere.com/v1/docs/playground-overview) | ||
|
||
|
||
## Installation | ||
|
||
To install the Cohere SDK, choose from the following 4 languages: | ||
|
||
<Tabs> | ||
<Tab title="Python"> | ||
|
||
```bash | ||
pip install -U cohere | ||
``` | ||
[Source](https://github.com/cohere-ai/cohere-python) | ||
</Tab> | ||
|
||
<Tab title="TypeScript"> | ||
|
||
```bash | ||
npm i -s cohere-ai | ||
``` | ||
[Source](https://github.com/cohere-ai/cohere-typescript) | ||
|
||
</Tab> | ||
|
||
<Tab title="Java"> | ||
|
||
```gradle | ||
implementation 'com.cohere:cohere-java:1.x.x' | ||
``` | ||
[Source](https://github.com/cohere-ai/cohere-java) | ||
|
||
</Tab> | ||
|
||
<Tab title="Go"> | ||
|
||
```bash | ||
go get github.com/cohere-ai/cohere-go/v2 | ||
``` | ||
|
||
[Source](https://github.com/cohere-ai/cohere-go) | ||
|
||
</Tab> | ||
</Tabs> |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
--- | ||
title: Retrieval Augmented Generation (RAG) | ||
slug: /docs/rag-quickstart | ||
|
||
description: "A quickstart guide for performing retrieval augmented generation (RAG) with Cohere's Command models (v1 API)." | ||
image: "../../../assets/images/f1cc130-cohere_meta_image.jpg" | ||
keywords: "Cohere, RAG, retrieval augmented generation, chatbot, command models" | ||
--- | ||
|
||
Retrieval Augmented Generation (RAG) enables an LLM to ground its responses on external documents, thus improving the accuracy of its responses and minimizing hallucinations. | ||
|
||
The Chat endpoint comes with built-in RAG capabilities such as document grounding and citation generation. | ||
|
||
This quickstart guide shows you how to perform RAG with the Chat endpoint. | ||
|
||
<Steps> | ||
### Setup | ||
First, install the Cohere Python SDK with the following command. | ||
|
||
```bash | ||
pip install -U cohere | ||
``` | ||
|
||
Next, import the library and create a client. | ||
|
||
<Tabs> | ||
<Tab title="Cohere Platform"> | ||
|
||
```python PYTHON | ||
import cohere | ||
|
||
co = cohere.Client("COHERE_API_KEY") # Get your free API key here: https://dashboard.cohere.com/api-keys | ||
``` | ||
|
||
</Tab> | ||
<Tab title="Private Deployment"> | ||
|
||
```python PYTHON | ||
import cohere | ||
|
||
co = cohere.Client( | ||
api_key="", # Leave this blank | ||
base_url="<YOUR_DEPLOYMENT_URL>" | ||
) | ||
``` | ||
|
||
</Tab> | ||
|
||
<Tab title="Bedrock"> | ||
|
||
```python PYTHON | ||
import cohere | ||
|
||
co = cohere.BedrockClient( | ||
aws_region="AWS_REGION", | ||
aws_access_key="AWS_ACCESS_KEY_ID", | ||
aws_secret_key="AWS_SECRET_ACCESS_KEY", | ||
aws_session_token="AWS_SESSION_TOKEN", | ||
) | ||
|
||
# Get the model name: https://docs.aws.amazon.com/bedrock/latest/userguide/models-supported.html | ||
``` | ||
</Tab> | ||
|
||
<Tab title="SageMaker"> | ||
|
||
```python PYTHON | ||
import cohere | ||
|
||
co = cohere.SagemakerClient( | ||
aws_region="AWS_REGION", | ||
aws_access_key="AWS_ACCESS_KEY_ID", | ||
aws_secret_key="AWS_SECRET_ACCESS_KEY", | ||
aws_session_token="AWS_SESSION_TOKEN", | ||
) | ||
``` | ||
</Tab> | ||
|
||
<Tab title="Azure AI"> | ||
|
||
```python PYTHON | ||
import cohere | ||
|
||
co = cohere.Client( | ||
api_key="AZURE_API_KEY", | ||
base_url="AZURE_ENDPOINT", | ||
) | ||
``` | ||
</Tab> | ||
|
||
</Tabs> | ||
|
||
### Documents | ||
|
||
First, define the documents that will passed as the context for RAG. These documents are typically retrieved from sources such as vector databases via semantic search, or any system that can retrieve unstructured data given a user query. | ||
|
||
Each document can take any number of fields e.g. `title`, `url`, `text`, etc. | ||
|
||
```python PYTHON | ||
documents = [ | ||
{ | ||
"text": "Reimbursing Travel Expenses: Easily manage your travel expenses by submitting them through our finance tool. Approvals are prompt and straightforward." | ||
}, | ||
{ | ||
"text": "Health and Wellness Benefits: We care about your well-being and offer gym memberships, on-site yoga classes, and comprehensive health insurance." | ||
}, | ||
] | ||
``` | ||
### Response Generation | ||
|
||
Next, call the Chat API by passing the documents in the `documents` parameter. This tells the model to run in RAG-mode and use these documents as the context in its response. | ||
|
||
<Tabs> | ||
<Tab title="Cohere Platform"> | ||
```python PYTHON | ||
message = "Are there fitness-related benefits?" | ||
|
||
response = co.chat( | ||
model="command-r-plus-08-2024", | ||
message=message, | ||
documents=documents | ||
) | ||
|
||
print(response.text) | ||
``` | ||
</Tab> | ||
|
||
<Tab title="Private Deployment"> | ||
```python PYTHON | ||
message = "Are there fitness-related benefits?" | ||
|
||
response = co.chat( | ||
model="command-r-plus-08-2024", | ||
message=message, | ||
documents=documents | ||
) | ||
|
||
print(response.text) | ||
``` | ||
</Tab> | ||
|
||
<Tab title="Bedrock"> | ||
```python PYTHON | ||
message = "Are there fitness-related benefits?" | ||
|
||
response = co.chat( | ||
model="YOUR_MODEL_NAME", | ||
message=message, | ||
documents=documents | ||
) | ||
|
||
print(response.text) | ||
``` | ||
</Tab> | ||
|
||
<Tab title="SageMaker"> | ||
```python PYTHON | ||
message = "Are there fitness-related benefits?" | ||
|
||
response = co.chat( | ||
model="YOUR_ENDPOINT_NAME", | ||
message=message, | ||
documents=documents | ||
) | ||
|
||
print(response.text) | ||
``` | ||
</Tab> | ||
|
||
<Tab title="Azure AI"> | ||
```python PYTHON | ||
message = "Are there fitness-related benefits?" | ||
|
||
response = co.chat( | ||
message=message, | ||
documents=documents | ||
) | ||
|
||
print(response.text) | ||
``` | ||
</Tab> | ||
</Tabs> | ||
|
||
```mdx wordWrap | ||
Yes, we offer gym memberships, on-site yoga classes, and comprehensive health insurance. | ||
|
||
``` | ||
|
||
### Citation Generation | ||
|
||
The response object contains a `citations` field, which contains specific text spans from the documents on which the response is grounded. | ||
|
||
```python PYTHON | ||
if response.citations: | ||
for citation in response.citations: | ||
print(citation, "\n") | ||
``` | ||
|
||
```mdx wordWrap | ||
start=14 end=88 text='gym memberships, on-site yoga classes, and comprehensive health insurance.' document_ids=['doc_1'] | ||
|
||
``` | ||
|
||
</Steps> | ||
|
||
## Further Resources | ||
- [Chat endpoint API reference](https://docs.cohere.com/v1/reference/chat) | ||
- [Documentation on RAG](https://docs.cohere.com/v1/docs/retrieval-augmented-generation-rag) | ||
- [LLM University module on RAG](https://cohere.com/llmu#rag) |
Oops, something went wrong.