Skip to main content

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.

Using pre-commit for a Smoother Contribution Experience

To ensure consistent code quality and avoid common pitfalls, we use pre-commit hooks in our development process. Before you submit your pull request, it's recommended that you set up pre-commit to ensure your changes adhere to our coding standards and guidelines.

Steps to set up pre-commit:

  1. Install pre-commit: If you haven't already, install packages including pre-commit:

    poetry install
    
  2. Activate pre-commit for the repository: Navigate to the root directory of this repository and run:

    pre-commit install
    

License

This project is licensed under the MIT License.


Feel free to customize the content based on your package's details and specific requirements.

Of course! Here's a message you can include in your README.md file to encourage contributors to use pre-commit:


Contributing to [Your Project Name]

Using pre-commit for a Smoother Contribution Experience

To ensure consistent code quality and avoid common pitfalls, we use pre-commit hooks in our development process. Before you submit your pull request, it's recommended that you set up pre-commit to ensure your changes adhere to our coding standards and guidelines.

Steps to set up pre-commit:

  1. Install pre-commit: If you haven't already, install pre-commit:

    pip install pre-commit
    
  2. Activate pre-commit for the repository: Navigate to the root directory of this repository and run:

    pre-commit install
    
  3. Run pre-commit on all files (optional): If you want to run the hooks on all the files in the repository (useful for the first-time setup):

    pre-commit run --all-files
    

With pre-commit set up, before every commit, the hooks will automatically check your changes and ensure they meet the repository's guidelines. If any issues are found, pre-commit will notify you, and in some cases, it might auto-fix the problems.

We appreciate your contribution and effort, and by setting up pre-commit, you're helping us maintain the quality and consistency of the project. Thank you!


Make sure to customize the placeholder [Your Project Name] with the actual name of your project. Adjust any other details as needed to better fit the specifics of your project or your desired messaging style.

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

vec_cache-0.1.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vec_cache-0.1.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file vec_cache-0.1.1.tar.gz.

File metadata

  • Download URL: vec_cache-0.1.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.17 Linux/5.15.0-1042-azure

File hashes

Hashes for vec_cache-0.1.1.tar.gz
Algorithm Hash digest
SHA256 9c505f12ef22f52067c5c0b66243ec24b0fa8ab7130db8b33ec76afae333816f
MD5 d10212f5587a88bca7a00ab9f82b7e97
BLAKE2b-256 8dcdcad7a87ceaf40e21e91ca6fa1add4abe1bce87075bc65e117082bf227319

See more details on using hashes here.

File details

Details for the file vec_cache-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: vec_cache-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.5.1 CPython/3.9.17 Linux/5.15.0-1042-azure

File hashes

Hashes for vec_cache-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9b9a272a229608579fabf877990e799f821ea405fdf17f6d82fccf49ec6caf4b
MD5 53e9ebb6abc4454069f43f291bd47bef
BLAKE2b-256 a90ee9497ea1290d472da81ea9e0aa49f563efa49263dcf318d34c21c9c55a7c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page