A simple function to retrieve sentence embeddings from an OpenAI Embeddings-compatible API.
Project description
retrieve-sentence-embeddings
A simple function to retrieve sentence embeddings from an OpenAI Embeddings-compatible API. That includes:
- OpenAI's embedding models (
base_url='https://api.openai.com/v1) - Google Gemini (
base_url='https://generativelanguage.googleapis.com/v1beta/openai') - ollama (
base_url='http://localhost:11434/v1').
with compatible models.
Features
- Compatibility: Unlike openai, works on Python 2+ with zero non-Python dependencies.
Installation
pip install retrieve-sentence-embeddings
Usage
# coding=utf-8
from retrieve_sentence_embeddings import retrieve_sentence_embeddings
api_key = u'OPENAI_API_KEY'
base_url = u'https://api.openai.com/v1'
model = u'text-embedding-ada-002'
sentences = [
u'Hello, world!',
u'This is a test sentence.',
u'Embeddings are useful!'
]
sentence_embeddings = retrieve_sentence_embeddings(api_key, base_url, model, sentences)
sentence_embeddings is a List[List[float]], e.g.,
[
[0.123, -0.982, ...],
[0.222, 0.088, ...],
...
]
Error Handling
If a network error or malformed response is encountered, the exception is propagated.
Contributing
Contributions are welcome! Please submit pull requests or open issues on the GitHub repository.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file retrieve_sentence_embeddings-0.1.0a0.tar.gz.
File metadata
- Download URL: retrieve_sentence_embeddings-0.1.0a0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c0e5f54ff68a24d8c233c0c2ab30b7161d3849ca8a908222577a178efabe0fed
|
|
| MD5 |
3815847e674ba2139c1e2c322352ef52
|
|
| BLAKE2b-256 |
d595255a27703df5fa9f86b3615c448783cb5467794205e71a31b394ba56cfcc
|
File details
Details for the file retrieve_sentence_embeddings-0.1.0a0-py2.py3-none-any.whl.
File metadata
- Download URL: retrieve_sentence_embeddings-0.1.0a0-py2.py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b02d95d81dc43830025428e57f5a4fd8496d3e348a8b56ad2707edb417800746
|
|
| MD5 |
c408aded50014d26fccd658865b0ddcd
|
|
| BLAKE2b-256 |
1b4f18a454c9920d985116bac6c7f59ea1ab0675a062a0abf53dd440065688d3
|