Skip to main content

LLM Hippocampus — a Context Engineering playground

Project description

🚀 LLM Hippocampus

License: MIT Language GitHub last commit Python

🎯 Build up and manage the LLM 's memory

🔥 LLM Hippocampus helping your project for building and experimenting with Context Engineering applications. harness the full power of Redis for lightning-fast vector search, intelligent semantic caching, persistent LLM memory, and **smart context engineering **.

What makes this special?

  • 🚀 One-command setup - pip install llm-hippocampus
  • LLM support - OpenAI
  • 🎯 Redis-powered - Vector search, caching, and memory management
  • 🐳 Docker ready - Building...
  • 🔧 Developer-first - Support to Hot load by installing llm-hippocampus

Table of Contents

Quick Start

Get up and install in your project:

pip install llm-hippocampus
or
uv add llm-hippocampus

Welcome to LLM Hippocampus! 🎉


Prerequisites

  1. Make sure you have the following tools available:
  2. Setup one or more of the following:

Getting Started

from dotenv import load_dotenv
from llm_hippocampus import env
from llm_hippocampus.core.utils import list2np_array
from llm_hippocampus.core.redis import create_search_index, client, load_data2search_index, vector_query
from llm_hippocampus.session import Session
load_dotenv()
# Load the model
session = Session()
embeddings = session.get_embedding_model()
schema = {
    "index": {
        "name": "data_agent_chain",
        "prefix": "data_agent_chain",
    },
    "fields": [
        {"name": "query", "type": "text"},
        {"name": "scope", "type": "text"},
        {"name": "intent", "type": "text"},
        {
            "name": "query_embedding",
            "type": "vector",
            "attrs": {
                "dims": 768,
                "distance_metric": "cosine",
                "algorithm": "flat",
                "datatype": "float32"
            }
        }
    ]
}

data = [
    {
        'query': 'SAAJ91的管理费率和托管费率是多少?',
        'scope': "产品基本信息",
        'intent': '管理费率、托管费率',
        'query_embedding': list2np_array(embeddings.encode(
            "SAAJ91的管理费率和托管费率是多少?",
            precision=schema["fields"][3]["attrs"]["datatype"],
            truncate_dim=schema["fields"][3]["attrs"]["dims"])).tobytes()
    },
    {
        'query': 'SATP77在于2025年06月01日至2025年06月30日的股票持仓明细',
        'scope': "股票持仓信息",
        'intent': '股票持仓信息',
        'query_embedding': list2np_array(embeddings.encode(
            "SATP77在于2025年06月01日至2025年06月30日的股票持仓明细",
            precision=schema["fields"][3]["attrs"]["datatype"],
            truncate_dim=schema["fields"][3]["attrs"]["dims"])).tobytes()
    },
    {
        'query': '截至于2025年01月01日至2025年12月31日,001120的户均定投金额?',
        'scope': "客户定投情况",
        'intent': '客户定投情况',
        'query_embedding': list2np_array(embeddings.encode(
            "截至于2025年01月01日至2025年12月31日,001120的户均定投金额",
            precision=schema["fields"][3]["attrs"]["datatype"],
            truncate_dim=schema["fields"][3]["attrs"]["dims"])).tobytes()
    }
]

redis_client = client(env.REDIS_URL)
index = create_search_index(redis_client, schema)
keys = load_data2search_index(index, data)

query = "400001的管理费率"
args = {
    "distance_threshold": session.distance_threshold,
    "top_k": session.top_k,
    "vector_field_name": "query_embedding",
    "precision": schema["fields"][3]["attrs"]["datatype"],
    "truncate_dim": schema["fields"][3]["attrs"]["dims"],
    "return_fileds": ["query", "scope", "intent"],
}

results = vector_query(query, index, embeddings, schema, **args)

Development Workflows

  • Building

Project Structure

Contributing

🤝 Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Troubleshooting

Learn More

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

llm_hippocampus-0.0.5.tar.gz (17.8 kB view details)

Uploaded Source

Built Distribution

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

llm_hippocampus-0.0.5-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file llm_hippocampus-0.0.5.tar.gz.

File metadata

  • Download URL: llm_hippocampus-0.0.5.tar.gz
  • Upload date:
  • Size: 17.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for llm_hippocampus-0.0.5.tar.gz
Algorithm Hash digest
SHA256 97452ebe538703793f205e102fa8fd34786295423c941e0a7d916f310a0fd6ae
MD5 4adf402b3cf42bbc990e61185ec902e2
BLAKE2b-256 67d8f6b6691a41733be31db90ae0317485977de59302fa27ee16a56323e18511

See more details on using hashes here.

File details

Details for the file llm_hippocampus-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_hippocampus-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4829ab4ab6aff9eee1658e4e14ea6cfe7a0de6beb635527b192253b69cac3ca4
MD5 3e98454df05907881f78a946179234a3
BLAKE2b-256 8857a1463b737afb24be2a4b1304caaf989f648b07d2cf1157237a9d6d894c70

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