# mixedbread ai Python SDK
## Table of Contents
- [Requirements](#requirements)
- [Installation](#installation)
- [Quick Start](#quick-start)
- [Usage](#usage)
- [Embeddings](#embeddings)
- [Reranking](#reranking)
- [Error Handling](#error-handling)
- [API Documentation](#api-documentation)
## Requirements
- Python 3.8+
## Installation
You can install directly using:
```sh
pip install mixedbread-ai
```
## Quick Start
Here's a minimal example to get started with the mixedbread ai SDK:
```python
from mixedbread_ai.client import MixedbreadAI
mxbai = MixedbreadAI(api_key="{YOUR_API_KEY}")
embeddings = mxbai.embeddings(
model="mixedbread-ai/mxbai-embed-large-v1",
input=["I like to eat apples."]
)
print(embeddings)
```
## Usage
### Embeddings
Here's an example of using the mixedbread ai SDK to create basic embeddings:
```python
from mixedbread_ai.client import MixedbreadAI
mxbai = MixedbreadAI(api_key="{YOUR_API_KEY}")
embeddings = mxbai.embeddings(
model="mixedbread-ai/mxbai-embed-large-v1",
input=["I like to eat apples.", "I like to eat bananas."]
)
print(embeddings)
```
By providing a prompt, you can guide the model to produce embeddings that are optimized for your specific use-case or downstream task.
```python
from mixedbread_ai.client import MixedbreadAI
mxbai = MixedbreadAI(api_key="{YOUR_API_KEY}")
embeddings = mxbai.embeddings(
model="mixedbread-ai/mxbai-embed-large-v1",
input=["I like to eat apples.", "I like to eat bananas."],
prompt="Represent this sentence for searching relevant passages"
)
print(embeddings)
```
By specifying the encoding format, you can leverage f.e. binary embeddings.
```python
from mixedbread_ai.client import MixedbreadAI
from mixedbread_ai.types import EncodingFormat
mxbai = MixedbreadAI(api_key="{YOUR_API_KEY}")
embeddings = mxbai.embeddings(
model="mixedbread-ai/mxbai-embed-large-v1",
input=["I like to eat apples.", "I like to eat bananas."],
encoding_format=[EncodingFormat.FLOAT, EncodingFormat.UBINARY]
)
print(embeddings.data[0].embedding.float_, embeddings.data[0].embedding.ubinary)
```
### Reranking (Asynchronous)
Here's an asynchronous example of using the mixedbread ai SDK to rerank documents:
```python
from mixedbread_ai.client import AsyncMixedbreadAI
mxbai_async = AsyncMixedbreadAI(api_key="{YOUR_API_KEY}")
model = "mixedbread-ai/mxbai-rerank-large-v1"
query = "Who wrote 'To Kill a Mockingbird'?"
documents = [
"'To Kill a Mockingbird' is a novel by Harper Lee published in 1960. It was immediately successful, winning the Pulitzer Prize, and has become a classic of modern American literature.",
"The novel 'Moby-Dick' was written by Herman Melville and first published in 1851. It is considered a masterpiece of American literature and deals with complex themes of obsession, revenge, and the conflict between good and evil.",
"Harper Lee, an American novelist widely known for her novel 'To Kill a Mockingbird', was born in 1926 in Monroeville, Alabama. She received the Pulitzer Prize for Fiction in 1961.",
"Jane Austen was an English novelist known primarily for her six major novels, which interpret, critique and comment upon the British landed gentry at the end of the 18th century.",
"The 'Harry Potter' series, which consists of seven fantasy novels written by British author J.K. Rowling, is among the most popular and critically acclaimed books of the modern era.",
"'The Great Gatsby', a novel written by American author F. Scott Fitzgerald, was published in 1925. The story is set in the Jazz Age and follows the life of millionaire Jay Gatsby and his pursuit of Daisy Buchanan."
]
reranked_docs = await mxbai_async.reranking(
model=model,
query=query,
input=documents
)
print(reranked_docs)
```
Don't forget to replace `"{YOUR_API_KEY}"` with your actual API key. If you don't have an API key, you can get one for free by signing up for an account at [mixedbread.ai](https://mixedbread.ai/).
## Error Handling and Retries
The SDK will raise errors if there is an issue with the API request, such as an invalid API key or a network error. Make sure to handle these exceptions in your code.
```python
from mixedbread_ai.client import MixedbreadAI, ApiError
from mixedbread_ai.types import EncodingFormat
mxbai = MixedbreadAI(api_key="{YOUR_API_KEY}")
try:
embeddings = mxbai.embeddings(
model="mixedbread-ai/mxbai-embed-large-v1",
input=["I like to eat apples.", "I like to eat bananas."],
encoding_format=[EncodingFormat.FLOAT, EncodingFormat.UBINARY],
request_options={
"max_retries": 3,
}
)
except ApiError as e:
print(e.status_code)
print(embeddings.data[0].embedding.float_, embeddings.data[0].embedding.ubinary)
```
## API Documentation
For more information on the available methods and options in the mixedbread ai SDK, please refer to our [API documentation](https://mixedbread.ai/api-reference).
Raw data
{
"_id": null,
"home_page": "https://github.com/mixedbread-ai/python-sdk.git",
"name": "mixedbread-ai",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "Embeddings, NLP, mixedbread.ai",
"author": "mixedbread.ai",
"author_email": "support@mixedbread.ai",
"download_url": "https://files.pythonhosted.org/packages/45/3a/a75d7ce08362eba640c4bfb2593998af7726401c251d77ac8de74c7c0624/mixedbread_ai-2.2.5.tar.gz",
"platform": null,
"description": "# mixedbread ai Python SDK\n\n## Table of Contents\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Quick Start](#quick-start)\n- [Usage](#usage)\n - [Embeddings](#embeddings)\n - [Reranking](#reranking)\n- [Error Handling](#error-handling)\n- [API Documentation](#api-documentation)\n\n## Requirements\n- Python 3.8+\n\n## Installation\nYou can install directly using:\n```sh\npip install mixedbread-ai\n```\n\n## Quick Start\nHere's a minimal example to get started with the mixedbread ai SDK:\n```python\nfrom mixedbread_ai.client import MixedbreadAI\n\nmxbai = MixedbreadAI(api_key=\"{YOUR_API_KEY}\")\n\nembeddings = mxbai.embeddings(\n model=\"mixedbread-ai/mxbai-embed-large-v1\",\n input=[\"I like to eat apples.\"]\n)\n\nprint(embeddings)\n```\n\n## Usage\n\n### Embeddings\n\nHere's an example of using the mixedbread ai SDK to create basic embeddings:\n```python\nfrom mixedbread_ai.client import MixedbreadAI\n\nmxbai = MixedbreadAI(api_key=\"{YOUR_API_KEY}\")\n\nembeddings = mxbai.embeddings(\n model=\"mixedbread-ai/mxbai-embed-large-v1\",\n input=[\"I like to eat apples.\", \"I like to eat bananas.\"]\n)\n\nprint(embeddings)\n```\n\nBy providing a prompt, you can guide the model to produce embeddings that are optimized for your specific use-case or downstream task.\n\n```python\nfrom mixedbread_ai.client import MixedbreadAI\n\nmxbai = MixedbreadAI(api_key=\"{YOUR_API_KEY}\")\n\nembeddings = mxbai.embeddings(\n model=\"mixedbread-ai/mxbai-embed-large-v1\",\n input=[\"I like to eat apples.\", \"I like to eat bananas.\"],\n prompt=\"Represent this sentence for searching relevant passages\"\n)\n\nprint(embeddings)\n```\n\nBy specifying the encoding format, you can leverage f.e. binary embeddings.\n\n```python\nfrom mixedbread_ai.client import MixedbreadAI\nfrom mixedbread_ai.types import EncodingFormat\n\nmxbai = MixedbreadAI(api_key=\"{YOUR_API_KEY}\")\n\nembeddings = mxbai.embeddings(\n model=\"mixedbread-ai/mxbai-embed-large-v1\",\n input=[\"I like to eat apples.\", \"I like to eat bananas.\"],\n encoding_format=[EncodingFormat.FLOAT, EncodingFormat.UBINARY]\n)\n\nprint(embeddings.data[0].embedding.float_, embeddings.data[0].embedding.ubinary)\n```\n\n### Reranking (Asynchronous)\nHere's an asynchronous example of using the mixedbread ai SDK to rerank documents:\n```python\nfrom mixedbread_ai.client import AsyncMixedbreadAI\n\nmxbai_async = AsyncMixedbreadAI(api_key=\"{YOUR_API_KEY}\")\n\nmodel = \"mixedbread-ai/mxbai-rerank-large-v1\"\nquery = \"Who wrote 'To Kill a Mockingbird'?\"\n\ndocuments = [\n \"'To Kill a Mockingbird' is a novel by Harper Lee published in 1960. It was immediately successful, winning the Pulitzer Prize, and has become a classic of modern American literature.\",\n \"The novel 'Moby-Dick' was written by Herman Melville and first published in 1851. It is considered a masterpiece of American literature and deals with complex themes of obsession, revenge, and the conflict between good and evil.\",\n \"Harper Lee, an American novelist widely known for her novel 'To Kill a Mockingbird', was born in 1926 in Monroeville, Alabama. She received the Pulitzer Prize for Fiction in 1961.\",\n \"Jane Austen was an English novelist known primarily for her six major novels, which interpret, critique and comment upon the British landed gentry at the end of the 18th century.\",\n \"The 'Harry Potter' series, which consists of seven fantasy novels written by British author J.K. Rowling, is among the most popular and critically acclaimed books of the modern era.\",\n \"'The Great Gatsby', a novel written by American author F. Scott Fitzgerald, was published in 1925. The story is set in the Jazz Age and follows the life of millionaire Jay Gatsby and his pursuit of Daisy Buchanan.\"\n]\n\nreranked_docs = await mxbai_async.reranking(\n model=model,\n query=query,\n input=documents\n)\n\nprint(reranked_docs)\n```\n\nDon't forget to replace `\"{YOUR_API_KEY}\"` with your actual API key. If you don't have an API key, you can get one for free by signing up for an account at [mixedbread.ai](https://mixedbread.ai/).\n\n\n## Error Handling and Retries\nThe SDK will raise errors if there is an issue with the API request, such as an invalid API key or a network error. Make sure to handle these exceptions in your code.\n\n```python\nfrom mixedbread_ai.client import MixedbreadAI, ApiError\nfrom mixedbread_ai.types import EncodingFormat\n\nmxbai = MixedbreadAI(api_key=\"{YOUR_API_KEY}\")\n\ntry:\n embeddings = mxbai.embeddings(\n model=\"mixedbread-ai/mxbai-embed-large-v1\",\n input=[\"I like to eat apples.\", \"I like to eat bananas.\"],\n encoding_format=[EncodingFormat.FLOAT, EncodingFormat.UBINARY],\n request_options={\n \"max_retries\": 3,\n }\n )\nexcept ApiError as e:\n print(e.status_code)\n\nprint(embeddings.data[0].embedding.float_, embeddings.data[0].embedding.ubinary)\n```\n\n\n## API Documentation\nFor more information on the available methods and options in the mixedbread ai SDK, please refer to our [API documentation](https://mixedbread.ai/api-reference).",
"bugtrack_url": null,
"license": "Apache-2.0",
"summary": "mixedbread ai (https://www.mixedbread.ai)",
"version": "2.2.5",
"project_urls": {
"Homepage": "https://github.com/mixedbread-ai/python-sdk.git",
"Repository": "https://github.com/mixedbread-ai/python-sdk.git"
},
"split_keywords": [
"embeddings",
" nlp",
" mixedbread.ai"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c9b170700723b0622553d12112aa0ed360b8a719a7f24629c093dfc644eeb60f",
"md5": "dfd8e59648ed8ab497b4b9e52f68077c",
"sha256": "8241a1d72b122f5a306f8c5ca7fd401953fa807288f2106378a336a461ad7c09"
},
"downloads": -1,
"filename": "mixedbread_ai-2.2.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "dfd8e59648ed8ab497b4b9e52f68077c",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 42336,
"upload_time": "2024-06-26T14:48:12",
"upload_time_iso_8601": "2024-06-26T14:48:12.509083Z",
"url": "https://files.pythonhosted.org/packages/c9/b1/70700723b0622553d12112aa0ed360b8a719a7f24629c093dfc644eeb60f/mixedbread_ai-2.2.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "453aa75d7ce08362eba640c4bfb2593998af7726401c251d77ac8de74c7c0624",
"md5": "69afcc81261a59570a4e4eca49d5b305",
"sha256": "0784aa0407e901d9a801109b6a0d452478456759a4a05a57a8435a5202f36a67"
},
"downloads": -1,
"filename": "mixedbread_ai-2.2.5.tar.gz",
"has_sig": false,
"md5_digest": "69afcc81261a59570a4e4eca49d5b305",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 20847,
"upload_time": "2024-06-26T14:48:14",
"upload_time_iso_8601": "2024-06-26T14:48:14.174468Z",
"url": "https://files.pythonhosted.org/packages/45/3a/a75d7ce08362eba640c4bfb2593998af7726401c251d77ac8de74c7c0624/mixedbread_ai-2.2.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-06-26 14:48:14",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "mixedbread-ai",
"github_project": "python-sdk",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "mixedbread-ai"
}