Ask HN:你们是如何在本地 Ollama 会话中处理持久性内存的?

2作者: null-phnix6 个月前
我本地构建了许多小型 AI 工具,主要基于 Ollama。我经常遇到的问题是,每次会话都从零开始。无论我前一天晚上建立了什么上下文,无论模型学到了我喜欢什么样的结构,无论我们一起完成了什么未完成的推理,当我在新终端打开时,一切都消失了。 有一段时间,我只是在每次会话开始时手动粘贴上下文,这听起来有多痛苦,实际上就有多痛苦。最终,我构建了一个小型代理,它位于我的客户端和 Ollama 之间,试图解决这个问题。它嵌入最近的交互,将它们存储在本地,并在新会话开始时注入相关的片段。它运行良好,我现在每天都在使用它,但我构建它的方式就像一个没有正式计算机科学背景的人构建东西一样,这意味着我把它修补成型,而且我不太确定它的架构是否正确。 仍然困扰我的是范围界定。我同时进行几个不同的项目,我不希望一个项目的上下文渗透到另一个项目中。目前,我手动管理这个问题,基本上只是保持不同的目录并小心谨慎,但这感觉像是一种权宜之计,而不是解决方案。 我真心好奇其他人是如何解决这个问题的。您是使用向量数据库进行检索,还是使用纯文件,还是使用类似 MCP 的东西,或者您是否已经接受了本地会话是无状态的,并围绕此构建了您的工作流程?如果您已经干净利落地解决了范围界定问题,我真的很想知道您是如何做到的。
查看原文
I build a lot of small AI tools locally, mostly on top of Ollama, and the thing I keep running into is that every session starts from zero. Whatever context I built up the night before, whatever the model learned about how I like things structured, whatever half-finished reasoning we were working through together, it is just gone when I open a new terminal.<p>For a while I was just manually pasting in context at the start of every session which is exactly as painful as it sounds. Eventually I built a small proxy that sits between my client and Ollama and tries to solve this. It embeds recent interactions, stores them locally, and injects the relevant chunks when a new session starts. It works well enough that I actually use it every day now, but I built it the way someone with no formal CS background builds things, which means I patched it into shape and I am not totally confident the architecture is right.<p>The part that still bothers me is scoping. I work on a few different projects at the same time and I do not want context from one bleeding into another. Right now I am managing that by hand, basically just keeping separate directories and being careful, but that feels like a workaround not a solution.<p>Genuinely curious what other people have landed on. Are you using a vector DB for retrieval, or plain files, or something MCP based, or have you just accepted that local sessions are stateless and built your workflow around that? And if you have solved the scoping problem cleanly I really want to know how.