Examples
Generate Text EmbeddingsCopy
The Generate text embeddings 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.
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 embeddingsCopy
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:
1[2{3"plantCategory": "Flowering Plants",4"name": "Anthuriums",5"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.",6"id": "bb38339175d5433f59c174503641ee9f"7},8{9"plantCategory": "Succulents",10"name": "Giant Velvet Rose",11"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.",12"id": "2dd678cc9ae05e3d78c7118c144fbd47"13},14{15"plantCategory": "Flowering Plants",16"name": "Peace Lily",17"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.",18"id": "ea52a8027170800f9cedbcd1cbdbed3a"19},20{21"plantCategory": "Succulents",22"name": "Zebra Plant",23"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.",24"id": "a3ad62c646467c729d83af4ab96fb8f1"25},26{27"plantCategory": "Flowering Plants",28"name": "Bromeliad",29"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.",30"id": "7cbccf5a735ed4f5cbec85f0bf9a0766"31}32]
You can then loop through this data, passing each item one by one to the Create embedding operation to generate embeddings.
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.
Generate query embeddingsCopy
The following scenario shows a query coming in through a Webhook and being sent to Cohere to create query embedding.
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.
Generate ChatCopy
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.
For a detailed understanding of the parameters involved, refer to Cohere's Chat API documentation.