请问HN:在构建大型语言模型应用时,你们是如何处理用户上下文的?

2作者: marcospassos9 个月前原帖
我一直在使用大型语言模型(LLMs)构建各种应用,每当我需要用户上下文时,最终都得手动搭建一个上下文管道。 当然,模型可以很好地推理和回答问题,但它对用户是谁、来自哪里或在应用中做了什么一无所知。如果没有这些信息,我要么让模型提出尴尬的初始问题来弄清楚,要么让它猜测,而通常猜测是错误的。 所以我不断重建相同的设置:跟踪事件、丰富会话、总结行为,并将这些信息注入到提示中。 这使得应用变得更加有帮助,但过程非常繁琐。 我希望能有一种简单的方法来获取会话摘要或用户上下文,这样我就可以直接放入提示中。类似于: ```javascript const context = await getContext(); const response = await generateText({ system: `这是用户上下文:${context}`, messages: [...] }); ``` 以下是我如何使用这个的几个例子: - 在支持方面,我传入他们查看的文档或他们访问的错误页面。 - 在营销方面,我总结他们的旅程,比如“点击广告” → “阅读博客文章” → “查看定价页面”。 - 在销售方面,我强调一些行为,以判断他们是初创公司还是企业。 - 在产品方面,我将会话分类为“困惑”、“探索方案”或“准备购买”。 - 在推荐方面,我从最近的活动中生成嵌入,并利用这些信息更准确地匹配内容或产品。 在所有这些情况下,我通常会注入一些信息,比如最近的活动、时区、货币、流量来源以及我能收集到的任何信号,以帮助引导用户体验。 还有其他人遇到过同样的问题吗?找到更好的解决方案了吗? 我正在考虑围绕这个问题构建一些东西,最初是为了自己解决这个问题。我很想听听其他人是如何处理的,或者这对你来说是否有用。
查看原文
I&#x27;ve been building stuff with LLMs, and every time I need user context, I end up manually wiring up a context pipeline.<p>Sure, the model can reason and answer questions well, but it has zero idea who the user is, where they came from, or what they&#x27;ve been doing in the app. Without that, I either have to make the model ask awkward initial questions to figure it out or let it guess, which is usually wrong.<p>So I keep rebuilding the same setup: tracking events, enriching sessions, summarizing behavior, and injecting that into prompts.<p>It makes the app way more helpful, but it&#x27;s a pain.<p>What I wish existed is a simple way to grab a session summary or user context I could just drop into a prompt. Something like:<p>const context = await getContext();<p>const response = await generateText({ system: `Here&#x27;s the user context: ${context}`, messages: [...] });<p>Some examples of how I use this:<p>- For support, I pass in the docs they viewed or the error page they landed on. - For marketing, I summarize their journey, like &#x27;ad clicked&#x27; → &#x27;blog post read&#x27; → &#x27;pricing page&#x27;. - For sales, I highlight behavior that suggests whether they&#x27;re a startup or an enterprise. - For product, I classify the session as &#x27;confused&#x27;, &#x27;exploring plans&#x27;, or &#x27;ready to buy&#x27;. - For recommendations, I generate embeddings from recent activity and use that to match content or products more accurately.<p>In all of these cases, I usually inject things like recent activity, timezone, currency, traffic source, and any signals I can gather that help guide the experience.<p>Has anyone else run into this same issue? Found a better way?<p>I&#x27;m considering building something around this initially to solve my problem. I&#x27;d love to hear how others are handling it or if this sounds useful to you.