A memory framework for Large Language Models and Agents
Project description
Join the redcache-ai discord server | Email me
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
Install redcache-ai as a python package
pip install redcache-ai
Initialize Redcache-ai
Redcache-ai provides two options. Initialize to disk or sqlite. By default redcache-ai initializes to disk. This where memories are 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 = DiskStorage()
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-ai 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.
What's Next ✈️
Redcache-ai is still early. Priority is to fix any and all existing bugs. Improve documentation then:
1.Add integration with more LLM providers including Llama, Mixtral, Claude etc.
2.Add functionality for AI Agents.
3.Provide support for a hosted version.
Happy memory building. ❤️
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.1.tar.gz.
File metadata
- Download URL: redcache_ai-0.1.1.tar.gz
- Upload date:
- Size: 13.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff2a0574b69bd29c6a3072c1328abaefcdebc070790495b6a4f0792a69742df9
|
|
| MD5 |
6ddd902980615b10bd40e7079cf974b6
|
|
| BLAKE2b-256 |
420065fb96a097254bf413822f1494d62bf762e1f7a7e824b358222244821eb7
|
File details
Details for the file redcache_ai-0.1.1-py3-none-any.whl.
File metadata
- Download URL: redcache_ai-0.1.1-py3-none-any.whl
- Upload date:
- Size: 13.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
30b954718b917d18d5b1b1d893859e98c8eb4f8296e5b3aff84d77010384d2fd
|
|
| MD5 |
9f42145d4ed3cd1ffe9b25a8b684ac91
|
|
| BLAKE2b-256 |
ab0a7a7d03a1745b59787dd9eceb5f066aff2dcdd4c69619232a343c2374bfc0
|