No project description provided
Project description
Sure! Below is a base README.md
for your Python package:
VecCache
VecCache is a Python package that provides an easy interface to cache embeddings of texts using OpenAI's API and allows for fast similarity searches over the cached embeddings.
Features
- Utilize OpenAI's API to generate text embeddings.
- Cache the embeddings efficiently using
faiss
. - Quick similarity searches over the cached embeddings.
Installation
pip install vec_cache
Note: You need to have an OpenAI API key to use this package.
Usage
Basic Usage
from vec_cache import VecCache
# Initialize the cache with your OpenAI API key. If openai_api_key is not provided, .env or environment variable is loaded.
cache = VecCache(ttl=3600, openai_api_key="YOUR_OPENAI_API_KEY")
# Store a text in the cache
cache.store("Hello, World!")
# Search for the most similar text in the cache
result = cache.search("Hi, World!")
print(result) # Outputs: "Hello, World!"
Storing with Precomputed Vectors
If you have precomputed vectors, you can store them directly:
vector = [0.1, 0.2, ...] # Some precomputed vector
cache.store_with_vector("Some text", vector)
Searching with Distance
If you wish to obtain the distance along with the result:
result, distance = cache.search("Hi, World!", return_with_distance=True)
print(result) # Outputs: "Hello, World!"
print(distance) # Outputs the L2 distance
Configuration
VecCache
accepts the following parameters:
ttl
: Time to live for cached vectors.openai_api_key
: Your OpenAI API key.embedding_model_name
: Name of the OpenAI embedding model. Default is "text-embedding-ada-002".vector_size
: Size of the vector. Default is 1536.
Contributions
We welcome contributions! Please submit a pull request or open an issue if you'd like to improve the package.
License
This project is licensed under the MIT License.
Feel free to customize the content based on your package's details and specific requirements.
Project details
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
File details
Details for the file vec_cache-0.1.0.tar.gz
.
File metadata
- Download URL: vec_cache-0.1.0.tar.gz
- Upload date:
- Size: 2.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.1 Linux/5.15.90.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c59e21c5fee012e94a5b9b67451e4d99aec26e4f6f67299a6d061cadff4eeadb |
|
MD5 | 489ba4b675aece25874aa77780a8d90a |
|
BLAKE2b-256 | 784b0ad225816d17b2a12fbf3c139684f19ab3354d1e1e6b96aa8347baf2e661 |
File details
Details for the file vec_cache-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: vec_cache-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.1 Linux/5.15.90.1-microsoft-standard-WSL2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e817aa45837ff8eefee6324374fae586141ea22f58fcf1cd5281f8dd85b43408 |
|
MD5 | 77362eed7c274bb74783748862944b10 |
|
BLAKE2b-256 | 6e06657f1820496de506906eeac08fc28d8475addf09b1201165103f3dc0adfa |