-
Notifications
You must be signed in to change notification settings - Fork 242
feat(memory): add token budgeting, fact summaries, and similarity ranking #975
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
feat(memory): add token budgeting, fact summaries, and similarity ranking #975
Conversation
b1e667e to
00e7086
Compare
|
Hi @fazlerahmanejazi! Could you please resolve the conflicts? :) |
…mory-enhancements
99ce88e to
784ab2d
Compare
784ab2d to
b742e55
Compare
Done @aozherelyeva, ready for review! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your pull request and contribution!
I see the idea as very valuable and practical, though there are some design suggestions that I propose to consider.
AgentMemoryProvider is already an interface that defines how to retrieve facts, and it's being used by AgentMemory feature. So I propose moving all additional filters, embedders and summarizers to some abstract class or implementation of that AgentMemoryProvider interface. Basically, you'd need to override suspend fun load(concept: Concept, subject: MemorySubject, scope: MemoryScope): List<Fact> and suspend fun save(fact: Fact, subject: MemorySubject, scope: MemoryScope) methods for that.
load can do the ranking, summarizing and filtering.
Additionally, please consider using ai.koog.rag.base.RankedDocumentStorage (https://docs.koog.ai/ranked-document-storage/) for ranking -- it's a generic interface that can be implemented via LLM embeddings + local storages as well as with vector databases (ai.koog.rag.vector.EmbeddingBasedDocumentStorage)
| * | ||
| * Implementations can wrap existing embedding infrastructure or provide lightweight in-memory behaviour. | ||
| */ | ||
| public interface EmbeddingProvider { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you please elaborate why ai.koog.embeddings.base.Embedder (and classes that implement it) doesn't fit here?
| } | ||
| } | ||
|
|
||
| private fun estimateTokens(text: String): Int = max(1, text.length / 4 + 1) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please consider checking ai.koog.prompt.tokenizer.Tokenizer interface (there's already a simple regex-based tokenizer implementation, as well as TiktokenEncoder)
|
@Ololoshechkin thanks again for the thoughtful review. I’ve pushed a set of changes that addresses each point:
Happy to dig into any of the details! |
Motivation and Context
Support configurable token budgets, summaries, and similarity ranking so memory injections stay concise and relevant.
AgentMemoryvia theSmartAgentMemoryProviderdecorator and sharedFactReplayProcessor(usesEmbedder,Tokenizer,RankedDocumentStorage; defaults keep legacy behaviour when the decorator isn’t applied).AgentMemoryEnhancementsTest,AgentMemoryEnrichmentTest)Breaking Changes
No breaking changes—new controls are optional and preserve existing defaults.
Type of the changes
Checklist
developas the base branchAdditional steps for pull requests adding a new feature