motorhead

getmetalApache-2.0长期未更新

给 LLM 应用提供记忆与信息检索能力的服务端,用 Rust 实现,帮你在对话中持久化上下文并做检索,省去自己搭记忆层。

🧠 Motorhead is a memory and information retrieval server for LLMs.

v3.0.2发布于 2023-12-19 03:18 UTC916star89fork同步于 2026-11-07 07:30 UTC

怎么上手

由 README 提炼,执行前请确认
docker-compose build && docker-compose up
docker run --name motorhead -p 8080:8080 -e PORT=8080 -e REDIS_URL='redis://redis:6379' -d ghcr.io/getmetal/motorhead:latest
硬件要求按 README 说明

README 未说明硬件要求,仅需能运行 Docker 并连接 Redis 的环境

有 Docker 镜像
下载:源码 zip·GitHub Releases(安装包)本站不镜像安装包

项目说明

由 README 自动翻译提炼

给 LLM 聊天应用提供会话记忆与检索的服务器,省去每次自己实现记忆管理

给 LLM 应用提供记忆与信息检索能力的服务端,用 Rust 实现,帮你在对话中持久化上下文并做检索,省去自己搭记忆层。

核心能力

  • 用 GET/POST/DELETE /sessions/:id/memory 管理会话消息
  • 窗口满后自动把一半消息增量摘要压缩上下文
  • 用 Redisearch VSS 按文本查询做会话内检索
  • 会话不存在时自动创建,检索自动按 session 过滤
  • 支持通过 context 字段从其他存储加载上下文

容易踩的坑

项目已标记 DEPRECATED,官方不再维护支持;必须提供 REDIS_URL,且长期记忆需开启 MOTORHEAD_LONG_TERM_MEMORY 并依赖 Redisearch VSS;摘要依赖 OPENAI_API_KEY,模型建议只用 gpt-3.5-turbo 或 gpt-4;README 中 PORT 默认值写 8000,但示例用 8080,需自行对齐端口

内容由模型根据 README 生成,可能不完整或不准确,以官方文档为准。看原文 README

最近发版

5 个版本v3.0.2
  1. v3.0.2最新正式版2023-12-19 · 2023-12-19 03:18 UTC

    What's Changed

    Full Changelog: https://github.com/getmetal/motorhead/compare/v3.0.1...v3.0.2

  2. v3.0.12023-11-14 · 2023-11-14 14:47 UTC
    查看更新说明
  3. v3.0.1rc12023-11-14 · 2023-11-14 14:44 UTC
    查看更新说明
  4. v3.0.02023-11-14 · 2023-11-14 14:15 UTC
    查看更新说明

    Breaking change

    • session changed from TEXT to TAG. This will change how data is indexed in Redisearch.

    ** If you have data already indexed, you can reindex it by dropping the index and restarting the server. FT.DROPINDEX motorhead. Do NOT use the DD option to keep the data and reindex it once the server restarts**

    What's Changed

    New Contributors

    Full Changelog: https://github.com/getmetal/motorhead/compare/v2.0.4...v3.0.0

  5. v2.0.4rc32023-08-23 · 2023-08-23 21:03 UTC
    查看更新说明

用户点评

登录用户的真实使用记录,可按版本和硬件筛选
共 0 条

    还没有人点评。第一个说出真实体验的人最有价值。

    README 原文

    未翻译

    Motorhead is a memory and information retrieval server for LLMs.

    Deploy on Railway

    Why use Motorhead?

    When building chat applications using LLMs, memory handling is something that has to be built every time. Motorhead is a server to assist with that process. It provides 3 simple APIs:

    • GET /sessions/:id/memory returns messages up to MAX_WINDOW_SIZE.
    {
        "messages": [
            {
                "role": "AI",
                "content": "Electronic music and salsa are two very different genres of music, and the way people dance to them is also quite different."
            },
            {
                "role": "Human",
                "content": "how does it compare to salsa?"
            },
            {
                "role": "AI",
                "content": "Electronic music is a broad genre that encompasses many different styles, so there is no one \"right\" way to dance to it."
            },
            {
                "role": "Human",
                "content": "how do you dance electronic music?"
            },
            {
                "role": "AI",
                "content": "Colombia has a vibrant electronic music scene, and there are many talented DJs and producers who have gained international recognition."
            },
            {
                "role": "Human",
                "content": "What are some famous djs from Colombia?"
            },
            {
                "role": "AI",
                "content": "Baum opened its doors in 2014 and has quickly become one of the most popular clubs for electronic music in Bogotá."
            }
        ],
        "context": "The conversation covers topics such as clubs for electronic music in Bogotá, popular tourist attractions in the city, and general information about Colombia. The AI provides information about popular electronic music clubs such as Baum and Video Club, as well as electronic music festivals that take place in Bogotá. The AI also recommends tourist attractions such as La Candelaria, Monserrate and the Salt Cathedral of Zipaquirá, and provides general information about Colombia's diverse culture, landscape and wildlife.",
        "tokens": 744 // tokens used for incremental summarization
    }
    
    • POST /sessions/:id/memory - Send an array of messages to Motorhead to store.
    curl --location 'localhost:8080/sessions/${SESSION_ID}/memory' \
    --header 'Content-Type: application/json' \
    --data '{
        "messages": [{ "role": "Human", "content": "ping" }, { "role": "AI", "content": "pong" }]
    }'
    

    Either an existing or new SESSION_ID can be used when storing messages, and the session is automatically created if it did not previously exist.

    Optionally, context can be send in if it needs to get loaded from another datastore.

    • DELETE /sessions/:id/memory - deletes the session's message list.

    A max window_size is set for the LLM to keep track of the conversation. Once that max is hit, Motorhead will process (window_size / 2 messages) and summarize them. Subsequent summaries, as the messages grow, are incremental.

    • POST /sessions/:id/retrieval - searches by text query using VSS.
    curl --location 'localhost:8080/sessions/${SESSION_ID}/retrieval' \
    --header 'Content-Type: application/json' \
    --data '{
        "text": "Generals gathered in their masses, just like witches in black masses"
    }'
    
    

    Searches are segmented (filtered) by the session id provided automatically.

    Config

    • MOTORHEAD_MAX_WINDOW_SIZE (default:12) - Number of max messages returned by the server. When this number is reached, a job is triggered to halve it.
    • MOTORHEAD_LONG_TERM_MEMORY (default:false) - Enables long term memory using Redisearch VSS.
    • MOTORHEAD_MODEL (default:gpt-3.5-turbo) - Model used to run the incremental summarization. Use gpt-3.5-turbo or gpt-4 - otherwise some weird things might happen.
    • PORT (default:8000) - Motorhead Server Port
    • OPENAI_API_KEY- Your api key to connect to OpenAI.
    • REDIS_URL (required)- URL used to connect to redis.
    • OPENAI_API_BASE (default:https://api.openai.com/v1) - OpenAI API Base URL

    Azure deployment

    Additional Environment Variables are required for Azure deployments:

    • AZURE_DEPLOYMENT_ID
    • AZURE_DEPLOYMENT_ID_ADA
    • AZURE_API_BASE
    • AZURE_API_KEY

    How to run

    With docker-compose:

    docker-compose build && docker-compose up
    

    Or you can use the image docker pull ghcr.io/getmetal/motorhead:latest directly:

    docker run --name motorhead -p 8080:8080 -e PORT=8080 -e REDIS_URL='redis://redis:6379' -d ghcr.io/getmetal/motorhead:latest
    

    Examples