Enhance Your Applications with E5-Mistral-7b-Instruct Text Embeddings

The cuuupid/e5-mistral-7b-instruct API offers powerful Cognitive Actions designed to help developers generate and improve text embeddings efficiently. By leveraging the E5-Mistral-7b-Instruct model, these actions provide high-quality, fine-tuned embeddings optimized for instruction-based tasks, making them ideal for a variety of applications such as natural language processing, semantic search, and more.
Prerequisites
Before diving into the integration of the Cognitive Actions, ensure you have the following:
- An API key for the Cognitive Actions platform.
- Basic understanding of JSON format and HTTP requests.
Authentication is typically handled by including your API key in the request headers as a bearer token. This ensures secure access to the services.
Cognitive Actions Overview
Embed Texts Using E5-Mistral-7b-Instruct
Description: This action generates and improves text embeddings using the E5-Mistral-7b-Instruct model, which is fine-tuned for instruction-based tasks. It creates high-quality embeddings with a context window of 32k tokens and 4096-length embedding vectors.
Category: Text Embedding
Input
The input for this action requires a structured JSON object with the following fields:
- texts (string, required): The URI of a JSONL file containing input texts. Each line in the file must be a JSON-stringified string to embed. The file should be directly accessible via a link.
- batchSize (integer, optional): The number of text items to process together in one batch during inference. The default value is 32.
- normalizeEmbeddings (boolean, optional): Indicates whether to apply normalization to the embeddings. The default value is true.
Example Input:
{
"texts": "https://replicate.delivery/pbxt/KLrAjasFNPYHr7SKynYHT1bbC63uUs6TMGcCcvxgmFAh9fLJ/embedding-text.json",
"batchSize": 1,
"normalizeEmbeddings": true
}
Output
The output of this action is typically a link to a JSON file containing the generated embeddings. The file will provide the embeddings as specified by the input parameters.
Example Output:
https://assets.cognitiveactions.com/invocations/ed1f6705-bf77-443b-ba6c-47fed28100aa/f7f85d3c-8202-4336-8206-2d14fb98ca95.json
Conceptual Usage Example (Python)
Here's a conceptual example of how you might call this action using Python. This snippet illustrates how to structure the input JSON payload and make a request to the hypothetical Cognitive Actions execution endpoint:
import requests
import json
# Replace with your Cognitive Actions API key and endpoint
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute" # Hypothetical endpoint
action_id = "8b4c288b-c085-4f9d-8b0e-31c55e21fdcf" # Action ID for Embed Texts Using E5-Mistral-7b-Instruct
# Construct the input payload based on the action's requirements
payload = {
"texts": "https://replicate.delivery/pbxt/KLrAjasFNPYHr7SKynYHT1bbC63uUs6TMGcCcvxgmFAh9fLJ/embedding-text.json",
"batchSize": 1,
"normalizeEmbeddings": true
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json"
}
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json={"action_id": action_id, "inputs": payload} # Hypothetical structure
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body: {e.response.text}")
In this example, replace YOUR_COGNITIVE_ACTIONS_API_KEY with your actual API key. The action_id variable is set to the ID of the action, and the payload variable contains the structured input JSON as required.
Conclusion
By integrating the E5-Mistral-7b-Instruct Cognitive Action into your applications, you can enhance the way your software processes and understands text. With its ability to generate high-quality embeddings tailored for instruction-based tasks, this action can significantly improve your application's performance in various natural language processing tasks. Consider exploring other potential use cases or combining this action with other Cognitive Actions to further enrich your application's capabilities.