> ## Documentation Index
> Fetch the complete documentation index at: https://ikun.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Cohere Embedder

`CohereEmbedder` 类用于通过 Cohere API 将文本数据嵌入到向量中。您可以从 [此处](https://docs.cohere.com/reference/about) 开始了解 Cohere。

从 [此处](https://dashboard.cohere.com/api-keys) 获取您的密钥。

## 用法

```python cookbook/embedders/cohere_embedder.py theme={null}
from agno.agent import AgentKnowledge
from agno.vectordb.pgvector import PgVector
from agno.embedder.cohere import CohereEmbedder

# 将嵌入添加到数据库
embeddings = CohereEmbedder().get_embedding("The quick brown fox jumps over the lazy dog.")
# 打印嵌入及其维度
print(f"Embeddings: {embeddings[:5]}")
print(f"Dimensions: {len(embeddings)}")

# 在知识库中使用 embedder
knowledge_base = AgentKnowledge(
    vector_db=PgVector(
        db_url="postgresql+psycopg://ai:ai@localhost:5532/ai",
        table_name="cohere_embeddings",
        embedder=CohereEmbedder(),
    ),
    num_documents=2,
)
```

## 参数

| 参数                | 类型                         | 默认值                    | 描述                                                                                            |
| ----------------- | -------------------------- | ---------------------- | --------------------------------------------------------------------------------------------- |
| `model`           | `str`                      | `"embed-english-v3.0"` | 用于生成嵌入的模型名称。                                                                                  |
| `input_type`      | `str`                      | `search_query`         | 要嵌入的输入类型。您可以在 [此处](https://docs.cohere.com/docs/embeddings#the-input_type-parameter) 找到更多详细信息 |
| `embedding_types` | `Optional[List[str]]`      | -                      | 要生成的嵌入类型。可选。                                                                                  |
| `api_key`         | `str`                      | -                      | 用于身份验证请求的 Cohere API 密钥。                                                                      |
| `request_params`  | `Optional[Dict[str, Any]]` | -                      | 要包含在 API 请求中的附加参数。可选。                                                                         |
| `client_params`   | `Optional[Dict[str, Any]]` | -                      | 用于配置 API 客户端的附加参数。可选。                                                                         |
| `cohere_client`   | `Optional[CohereClient]`   | -                      | 用于发出 API 请求的 CohereClient 实例。可选。                                                              |

## 开发者资源

* 查看 [Cookbook](https://github.com/agno-agi/agno/blob/main/cookbook/agent_concepts/knowledge/embedders/cohere_embedder.py)
