Cache for LLM, Multimodal LLM and embeddings
Overview
LaVague Context Cache is a caching layer designed for Language Models, Multimodal Language Models and embeddings. It ensures deterministic results, avoids unnecessary token consumption, and speeds up local development by caching responses and embeddings.
This tool is ideal for:
- Developers seeking to streamline their workflow when working with models.
- Builders aiming to reduce model costs and enhance performance when agent objectives are stable.
Key features:
- Guarantees consistent results in both automated and manual testing by caching previous responses
- Reduces API token consumption by reusing cached results, avoiding redundant API calls
- Speeds up local development by eliminating the need to repeatedly query the same results
- Cached scenario can be replayed offline
Installation
From pypi
pip install lavague-contexts-cache
From the sources
pip install -e lavague-integrations/contexts/lavague-contexts-cache
Usage
Using wrappers
from lavague.contexts.cache import LLMCache
from llama_index.llms.openai import OpenAI
llm = LLMCache(yml_prompts_file="llm.yml", fallback=OpenAI(model = "gpt-4o"))
from lavague.contexts.cache import MultiModalLLMCache
from llama_index.multi_modal_llms.openai import OpenAIMultiModal
mm_llm = MultiModalLLMCache(yml_prompts_file="mmllm.yml", fallback=OpenAIMultiModal(model = "gpt-4o"))
from lavague.contexts.cache import EmbeddingCache
from llama_index.embeddings.openai import OpenAIEmbedding
embedding = EmbeddingCache(yml_prompts_file="embeddings.yml", fallback=OpenAIEmbedding(model = "text-embedding-3-large"))
Using LaVague context
from lavague.core import WorldModel, ActionEngine
from lavague.core.agents import WebAgent
from lavague.drivers.selenium import SeleniumDriver
from lavague.core.context import get_default_context
from lavague.contexts.cache import ContextCache
driver = SeleniumDriver()
context = get_default_context()
cached_context = ContextCache.from_context(context)
world_model = WorldModel.from_context(cached_context)
action_engine = ActionEngine.from_context(cached_context, driver)
agent = WebAgent(world_model, action_engine)
Performance
Cached values are stored in YAML files and loaded into memory by default. While this approach works well for a few runs, it can consume excessive memory when applied to various websites. For production use cases, we recommend using an optimized storage system (database, cache, ...).
To do so, pass a store that implements abstract PromptsStore methods.
from lavague.contexts.cache import LLMCache
from lavague.contexts.cache.prompts_store import PromptsStore
from llama_index.llms.openai import OpenAI
class MyDataBaseStore(PromptsStore[str]):
def _get_for_prompt(self, prompt: str) -> str:
# return from DB with prompt key
pass
def _add_prompt(self, prompt: str, output: str):
# store in DB
pass
my_database_store = MyDataBaseStore()
llm = LLMCache(yml_prompts_file="llm.yml", fallback=OpenAI(model = "gpt-4o"), store=store)
Metadata
Release files for lavague-contexts-cache 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lavague_contexts_cache-0.0.1.tar.gz | 5.0 kB | Without provenance | Details for lavague_contexts_cache-0.0.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lavague_contexts_cache-0.0.1-py3-none-any.whl | Python 3 | none | any | Details for lavague_contexts_cache-0.0.1-py3-none-any.whl |
Total release size: 12.1 kB
Release files / lavague_contexts_cache-0.0.1.tar.gz
| Download URL | lavague_contexts_cache-0.0.1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
60706f05654f694b9e32a8c27783cf725d1e96b910500b588e0b1ea965c602d9
|
|
BLAKE2b-256 checksum How to use checksums |
99162f0644b551edacc34a7f95af98ccd2660df99b2cd5807342633f4de034da
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2
|
Release files / lavague_contexts_cache-0.0.1-py3-none-any.whl
| Download URL | lavague_contexts_cache-0.0.1-py3-none-any.whl |
|---|---|
| Size | 7.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95754f84b94ebb7e1449fb73097303efb4b9c13da6df0f26fc6a5e146e6d9d20
|
|
BLAKE2b-256 checksum How to use checksums |
f4ee9ac8096852da7ec8a242d7b5095a7086d01042ca720af9bad87a5da42161
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.3 CPython/3.10.12 Linux/5.15.153.1-microsoft-standard-WSL2
|
Security for lavague-contexts-cache 0.0.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.