Package: vec-cache
VecCacheVecCache 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.FeaturesUtilize OpenAI's API to generate text embeddings.Cache the embeddings efficiently usingfaiss.Quick similarity searches over the cached embeddings.Installationpipinstallvec_cacheNote: You need to have an OpenAI API key to use this package.UsageBasic Usagefromvec_cacheimportVecCache# 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 cachecache.store("Hello, World!")# Search for the most similar text in the cacheresult=cache.search("Hi, World!")print(result)# Outputs: "Hello, World!"Storing with Precomputed VectorsIf you have precomputed vectors, you can store them directly:vector=[0.1,0.2,...]# Some precomputed vectorcache.store_with_vector("Some text",vector)Searching with DistanceIf 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 distanceConfigurationVecCacheaccepts 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.ContributionsWe welcome contributions! Please submit a pull request or open an issue if you'd like to improve the package.Usingpre-commitfor a Smoother Contribution ExperienceTo ensure consistent code quality and avoid common pitfalls, we usepre-commithooks in our development process. Before you submit your pull request, it's recommended that you set uppre-committo ensure your changes adhere to our coding standards and guidelines.Steps to set uppre-commit:Installpre-commit:
If you haven't already, install packages includingpre-commit:poetryinstallActivatepre-commitfor the repository:
Navigate to the root directory of this repository and run:pre-commitinstallLicenseThis 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 yourREADME.mdfile to encourage contributors to usepre-commit:Contributing to [Your Project Name]Usingpre-commitfor a Smoother Contribution ExperienceTo ensure consistent code quality and avoid common pitfalls, we usepre-commithooks in our development process. Before you submit your pull request, it's recommended that you set uppre-committo ensure your changes adhere to our coding standards and guidelines.Steps to set uppre-commit:Installpre-commit:
If you haven't already, installpre-commit:pipinstallpre-commitActivatepre-commitfor the repository:
Navigate to the root directory of this repository and run:pre-commitinstallRunpre-commiton all files (optional):
If you want to run the hooks on all the files in the repository (useful for the first-time setup):pre-commitrun--all-filesWithpre-commitset 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-commitwill notify you, and in some cases, it might auto-fix the problems.We appreciate your contribution and effort, and by setting uppre-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.