# Examples

## Generate Text Embeddings

The [**Generate text embeddings**](https://docs.cohere.com/reference/embed) operation generates an embedding vector that represents input text.
The generated embeddings can be stored in any vector database and are valuable for performing [similarity searches](https://www.pinecone.io/learn/what-is-similarity-search/).
The two possible scenarios of text embedding are explained below:

1. Creating vector embeddings for your data
2. Querying your vector embeddings to retrieve information

### Generate docs embeddings

To generate document embeddings, you may need to handle batches of data.
Consider a scenario where you have received a chunk of data through a Webhook.
**Sample data:**

```json
[
    \{
        "plantCategory": "Flowering Plants",
        "name": "Anthuriums",
        "text": "These heart-shaped blooms require medium to bright light and thrive in humid conditions, making them great indoor plants. They come in various shades: pink, lavender and white, and will grow two to three feet tall.",
        "id": "bb38339175d5433f59c174503641ee9f"
    \},
    \{
        "plantCategory": "Succulents",
        "name": "Giant Velvet Rose",
        "text": "These heart-shaped blooms require medium to bright light and thrive in humid conditions, making them great indoor plants. They come in various shades: pink, lavender and white, and will grow two to three feet tall.",
        "id": "2dd678cc9ae05e3d78c7118c144fbd47"
    \},
    \{
        "plantCategory": "Flowering Plants",
        "name": "Peace Lily",
        "text": "Symbolizing fresh life and rebirth, peace lilies are known for their spoon-shaped flowers and easy care. Keep them in low to moderate light and make sure they're in moist soil. If you see them drooping, that's a sign they need watering.",
        "id": "ea52a8027170800f9cedbcd1cbdbed3a"
    \},
    \{
        "plantCategory": "Succulents",
        "name": "Zebra Plant",
        "text": "It has thick, dark green leaves with white horizontal stripes on the outside of the leaves.Haworthiopsis fasciata “Zebra Plant” has typical watering needs for a succulent. It's best to use the “soak and dry” method, and allow the soil to dry out completely between waterings.",
        "id": "a3ad62c646467c729d83af4ab96fb8f1"
    \},
    \{
        "plantCategory": "Flowering Plants",
        "name": "Bromeliad",
        "text": "Part of the pineapple family, bromeliads have tropical foliage pretty enough for holiday decorating. The blooms can last up to six months with proper care: Provide indirect bright light, keep the plants moist and maintain humid air conditions.",
        "id": "7cbccf5a735ed4f5cbec85f0bf9a0766"
    \}
]
```

You can then loop through this data, passing each item one by one to the **Create embedding** operation to generate embeddings.
![cohere-generate-embeddings-for-docs](https://tray.ai/documentation/images/connectors/artificial-intelligence/cohere/3NennSNV5JdVTHJrgswVPj_cohere-generate-embeddings-for-docs.png)
Since you are looping through batches of data for which you are creating vectors, you will need to create an object that adheres to this structure and append it to a data storage list.
For a more detailed guide to sending batches of vector data, please refer to the [Pinecone documentation](https://tray.ai/documentation/connectors/service/pinecone/#upsert-vectors).

### Generate query embeddings

The following scenario shows a query coming in through a Webhook and being sent to Cohere to create query embedding.
![cohere-generate-text-embeddings](https://tray.ai/documentation/images/connectors/artificial-intelligence/cohere/Km7uMZUrMWm5RwlNUAAdZ_cohere-generate-query-embeddings.png)
The resulting vector is then passed to a vector database to perform a similarity search.
For a detailed understanding of the parameters involved, refer to Cohere's [Embed API documentation.](https://docs.cohere.com/reference/embed)

## Generate Chat

Generates a model response for the given chat conversation.
The following example demonstrates one of the use cases for the operation.
It shows a query coming in through a Webhook and being sent to Cohere to create an embedding vector. The resulting vector is then passed to a vector database to perform a similarity search.
The **Generate chat** operation uses the similarity search result to Create a model response for the received query.
![cohere-generate-chat](https://tray.ai/documentation/images/connectors/artificial-intelligence/cohere/7BoqEQpshnFOQzz0oM2InJ_cohere-generate-chat.png)
For a detailed understanding of the parameters involved, refer to Cohere's [Chat API documentation](https://docs.cohere.com/reference/chat).
