A memory framework for Large Language Models and Agents
Project description
Join the redcache-ai discord server
RedCache-ai: A memory framework for Large Language Models and Agents
What ?
REmote Dictionary cache - Artificial Intelligence (RedCache-AI). While developing a chat application, every solution I came across was either expensive, closed source or lacked extensive support for external dependencies. Redcache-ai provides a dynamic memory framework for Large Language Models, enabling developers to build wide ranging applications, from AI-powered dating apps to healthcare diagnostics platforms.
Quickstart
Installation
To install redcache-ai run the following command using pip
pip install redcache-ai
Make sure all the requirements are installed
If requirements are not installed use:
pip install -r requirements.txt
Depending on the machine you're using, you might need to install setuptools in setup.py
pip install setuptools
Initialize Redcache-ai
Redcache-ai provides two options. Initialize to disk or sqlite. By default redcache initializes to disk. This is where the text memories will be stored.
Option 1: initialize to disk
Make sure to import all the required dependencies
from redcache_ai import RedCache, load_config, set_openai_api_key
from redcache_ai.storage import DiskStorage, SQLiteStorage
storage = Disktorage()
Option 2: Initialize to sqlite
storage = SQLiteStorage(db_path='my_cache.db')
Store text as memory
Note: the output visual representation below is for disk storage only. The input is the same for sqlite
Input
memory_cache = storage.add("England is nice country", user_id = "James", metadata={"category": "facts"})
Output
{"James": {"7bbfbcbf-da9e-44ca-9cbb-ab558c64b36a": {"id": "7bbfbcbf-da9e-44ca-9cbb-ab558c64b36a", "text": "\"England is a nice country\"", "metadata": {"data": "\"England is a nice country\"", "category": "facts"}, "vector": [0.4472135954999579]}}}
Retrieve Memory
# Get all memories
memories = storage(user_id = "James")
print(all_memories)
Output:
# Get all memories
[
{
"id": "7bbfbcbf-da9e-44ca-9cbb-ab558c64b36a",
"text": "England is a nice country",
"metadata": {
"category": "facts"
}
}
]
Search Memories
# Get all memories
results = storage.search("country", user_id="James", num_results=1)
Output:
[
{
"id": "7bbfbcbf-da9e-44ca-9cbb-ab558c64b36a",
"text": "England is a nice country",
"metadata": {
"category": "facts"
},
"score": 0.849
}
]
Update Memory
updated_memory = storage.update("7bbfbcbf-da9e-44ca-9cbb-ab558c64b36a", "England is a beautiful country", user_id="James")
Output:
{
"id": "7bbfbcbf-da9e-44ca-9cbb-ab558c64b36a",
"text": "England is a beautiful country",
"metadata": {
"category": "facts"
}
}
Delete Memory
storage.delete("7bbfbcbf-da9e-44ca-9cbb-ab558c64b36a", user_id="James")
Output:
# No output, memory is deleted if successful
Delete all memories
storage.delete_all(user_id="James")
# No output, all memories for the user are deleted if successful
Enhance a memory using LLMs
Large Langugae Model Integradtion
For now, redcache-ai only supports OpenAI. To integrate redcache memories into openAI, you have to set an OPENAI API Key.
Once you have the key, you'll integrate your text memories like this:
from redcache_ai.config import set_openai_api_key
set_openai_api_key("your-openai-api-key-here")
from redcache_ai import RedCache, load_config
# Load the default configuration
config = load_config()
# Initialize RedCache with OpenAI LLM
redcache = RedCache.from_config(config)
The output for load_config is below:
{
"llm": {
"provider": "openai",
"config": {
"model": "gpt-4",
"temperature": 0.2,
"max_tokens": 1500,
}
}
}
enhanced_memory = redcache.enhance_memory("England has a rich history", user_id="James", category="facts")
summary = redcache.generate_summary(user_id="James")
These examples demonstrate the basic usage of redcache-ai. For more detailed information and advanced features, please refer to the full documentation. If implementation details are unclear please see the test_redcache.py file in examples. For more information, visit the discord channel to build now and scale tomorrow :)
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 redcache_ai-0.1.0.tar.gz.
File metadata
- Download URL: redcache_ai-0.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe0b0833d2807dea6400928b7dbf987157f1546d5b2246f6c86f638988e950f2
|
|
| MD5 |
6274a37de5d0daf430246490c723b933
|
|
| BLAKE2b-256 |
dc02d999963f4c3df576cd7bf6cacfe190edb251e7a164d38b24cfbede40728a
|
File details
Details for the file redcache_ai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: redcache_ai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c1ac604158699a900af6fa32c987fb6fdaf79cf21f51fa3eb3fba125fbe5803
|
|
| MD5 |
614267f25fc4f29ac0b08e824029edbe
|
|
| BLAKE2b-256 |
7cfaa9ddcc04d80f15589f2a3189e45355365b5fe13180974a6cbd5fef3496c2
|