[GH-ISSUE #356] [Feature]: Agent Vector Store #152

Closed
opened 2026-10-20 17:25:41 +07:00 by bsakaguchi · 5 comments
Owner

Originally created by @adunato on GitHub (May 2, 2026).
Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/356

Originally assigned to: @SpicyMarinara on GitHub.

What problem does this solve?

Agents can call tools during generation, but they do not have a clean way to persist and retrieve arbitrary text as semantic memory.

The existing Memory Recall feature is not suitable for this. It stores automatic five-message chat chunks in memory_chunks, with message-specific fields such as messageCount, firstMessageAt, and lastMessageAt. It is designed for generated recall fragments from a chat, not custom tool-provided content.

The hidden [memory: ...] command is also not a suitable foundation. It writes ad hoc entries into character card extensions.characterMemories, with no dedicated table, stable IDs, vector search, or tool API.

Proposed solution

Add a tool-only agent vector store backed by a new agent_vector_chunks table. The feature should let agents write, search, list, and delete custom text chunks without changing the Memory Recall UI or automatically injecting results into prompts.

Proposed built-in tools:

  • vector_write
  • vector_search
  • vector_list
  • vector_delete

vector_write should accept custom content, optional namespace, optional structured metadata, and an optional model-facing scope such as chat, character, agent, or a combined scope. The model should not pass raw internal IDs.

vector_search should accept a semantic query, optional namespace, optional scope, and retrieval controls such as topK, similarityThreshold, and optional recency weighting. It should return matched chunks with ID, content, metadata, and similarity score.

vector_list should support non-semantic browsing by namespace and scope, with limit/cursor pagination, without exposing raw embeddings. vector_delete should remove or disable a stored chunk by ID.

The server should resolve concrete scope IDs during tool execution. Current code already has the required values before tool execution:

  • AgentContext.chatId is set from input.chatId.
  • AgentContext.characters contains active character IDs and names.
  • Each ResolvedAgent has the executing agent config ID as agent.id.

However, ToolExecutionContext currently does not expose these values. This change should extend it with chatId, active character IDs/names, and executing agentConfigId, so the tool executor can translate model-facing scopes into stored IDs. For character-scoped writes in multi-character chats, the tool input should include a character selector such as characterName, validated against the active character list.

Possible table direction:

agent_vector_chunks
- id
- namespace
- scopeType
- chatId
- characterId
- agentConfigId
- content
- embedding
- embeddingModel
- contentHash
- metadata
- enabled
- createdAt
- updatedAt

Retrieval should reuse the existing local embedding path and cosine-similarity approach used by Memory Recall: embed the query with localEmbed(), load bounded candidates by namespace/scope, score with cosine similarity, apply threshold/topK, and return scored matches.

Example agent policy:

Use namespace "continuity".

Call vector_write for stable facts, promises, unresolved tasks, decisions, or significant events that should persist beyond the current context.

Use scope "chat" for facts that only matter in this chat.
Use scope "character" plus the character name for facts that apply to one active character across chats.
Use scope "agent" for facts owned by this agent workflow.

Before answering questions about prior facts, plans, decisions, or continuity, call vector_search with namespace "continuity", the relevant scope, topK 5, and similarityThreshold 0.35.

Do not write routine small talk, transient emotion, repeated facts, or information already present in the active prompt.

Alternatives considered

  • Reuse memory_chunks. Rejected because that table and service are specifically shaped around automatic aggregated chat-message chunks.
  • Extend Memory Recall directly. Rejected for this CR because the requested feature is tool-driven storage/retrieval, not user-facing recall UI or automatic prompt injection.
  • Use lorebooks. Rejected because this would contaminate user-authored world/knowledge storage with agent-managed vector chunks.
  • Build on extensions.characterMemories. Rejected because it is stored inside character card JSON, has no stable IDs, no search, no dedicated DB table, and no clean tool API.
  • Introduce an external vector database. Rejected because the existing local embedding and SQLite JSON-vector pattern is sufficient for the first implementation.

Additional context

Relevant current implementation points:

  • Memory Recall stores generated chat chunks in memory_chunks.
  • Lorebook entries already use JSON-vector embedding storage.
  • ToolExecutionContext currently includes game state, chat metadata, custom tools, lorebook search, Spotify credentials, and metadata patching, but not chat/character/agent identity.
  • The implementation should add built-in tool definitions, storage/service code, schema migration, tool executor handling, and focused service/tool tests.

Template check

Please uncheck (untick) the box below before submitting so we know you read the template. It is intentionally pre-checked:

  • I DID NOT read this template and provide the requested details.
Originally created by @adunato on GitHub (May 2, 2026). Original GitHub issue: https://github.com/Pasta-Devs/Marinara-Engine/issues/356 Originally assigned to: @SpicyMarinara on GitHub. ## What problem does this solve? Agents can call tools during generation, but they do not have a clean way to persist and retrieve arbitrary text as semantic memory. The existing Memory Recall feature is not suitable for this. It stores automatic five-message chat chunks in `memory_chunks`, with message-specific fields such as `messageCount`, `firstMessageAt`, and `lastMessageAt`. It is designed for generated recall fragments from a chat, not custom tool-provided content. The hidden `[memory: ...]` command is also not a suitable foundation. It writes ad hoc entries into character card `extensions.characterMemories`, with no dedicated table, stable IDs, vector search, or tool API. ## Proposed solution Add a tool-only agent vector store backed by a new `agent_vector_chunks` table. The feature should let agents write, search, list, and delete custom text chunks without changing the Memory Recall UI or automatically injecting results into prompts. Proposed built-in tools: - `vector_write` - `vector_search` - `vector_list` - `vector_delete` `vector_write` should accept custom `content`, optional `namespace`, optional structured `metadata`, and an optional model-facing scope such as `chat`, `character`, `agent`, or a combined scope. The model should not pass raw internal IDs. `vector_search` should accept a semantic `query`, optional `namespace`, optional `scope`, and retrieval controls such as `topK`, `similarityThreshold`, and optional recency weighting. It should return matched chunks with ID, content, metadata, and similarity score. `vector_list` should support non-semantic browsing by namespace and scope, with limit/cursor pagination, without exposing raw embeddings. `vector_delete` should remove or disable a stored chunk by ID. The server should resolve concrete scope IDs during tool execution. Current code already has the required values before tool execution: - `AgentContext.chatId` is set from `input.chatId`. - `AgentContext.characters` contains active character IDs and names. - Each `ResolvedAgent` has the executing agent config ID as `agent.id`. However, `ToolExecutionContext` currently does not expose these values. This change should extend it with `chatId`, active character IDs/names, and executing `agentConfigId`, so the tool executor can translate model-facing scopes into stored IDs. For character-scoped writes in multi-character chats, the tool input should include a character selector such as `characterName`, validated against the active character list. Possible table direction: ```text agent_vector_chunks - id - namespace - scopeType - chatId - characterId - agentConfigId - content - embedding - embeddingModel - contentHash - metadata - enabled - createdAt - updatedAt ``` Retrieval should reuse the existing local embedding path and cosine-similarity approach used by Memory Recall: embed the query with `localEmbed()`, load bounded candidates by namespace/scope, score with cosine similarity, apply threshold/topK, and return scored matches. Example agent policy: ```text Use namespace "continuity". Call vector_write for stable facts, promises, unresolved tasks, decisions, or significant events that should persist beyond the current context. Use scope "chat" for facts that only matter in this chat. Use scope "character" plus the character name for facts that apply to one active character across chats. Use scope "agent" for facts owned by this agent workflow. Before answering questions about prior facts, plans, decisions, or continuity, call vector_search with namespace "continuity", the relevant scope, topK 5, and similarityThreshold 0.35. Do not write routine small talk, transient emotion, repeated facts, or information already present in the active prompt. ``` ## Alternatives considered - Reuse `memory_chunks`. Rejected because that table and service are specifically shaped around automatic aggregated chat-message chunks. - Extend Memory Recall directly. Rejected for this CR because the requested feature is tool-driven storage/retrieval, not user-facing recall UI or automatic prompt injection. - Use lorebooks. Rejected because this would contaminate user-authored world/knowledge storage with agent-managed vector chunks. - Build on `extensions.characterMemories`. Rejected because it is stored inside character card JSON, has no stable IDs, no search, no dedicated DB table, and no clean tool API. - Introduce an external vector database. Rejected because the existing local embedding and SQLite JSON-vector pattern is sufficient for the first implementation. ## Additional context Relevant current implementation points: - Memory Recall stores generated chat chunks in `memory_chunks`. - Lorebook entries already use JSON-vector embedding storage. - `ToolExecutionContext` currently includes game state, chat metadata, custom tools, lorebook search, Spotify credentials, and metadata patching, but not chat/character/agent identity. - The implementation should add built-in tool definitions, storage/service code, schema migration, tool executor handling, and focused service/tool tests. ## Template check Please **uncheck (untick)** the box below before submitting so we know you read the template. It is intentionally pre-checked: - [ ] I DID NOT read this template and provide the requested details.
bsakaguchi 2026-10-20 17:25:41 +07:00
Author
Owner

@SpicyMarinara commented on GitHub (May 3, 2026):

Changing some things in how we store data, so I have to refuse this for now.

<!-- gh-comment-id:4366564973 --> @SpicyMarinara commented on GitHub (May 3, 2026): Changing some things in how we store data, so I have to refuse this for now.
Author
Owner

@adunato commented on GitHub (May 4, 2026):

@SpicyMarinara thanks for the follow up! Makes sense, and the reason why I didn't start a PR on this. When planning data store next steps, it would be great to keep in mind agent custom data storage. The current storage solutions are all quite specific (lorebook semantic search, chat memories, memory recall), hence this ticket. But if there was an underlying way to store arbitrary data as part of the core engine, then you could build custom store management more easily without reinventing the wheel.

<!-- gh-comment-id:4369948460 --> @adunato commented on GitHub (May 4, 2026): @SpicyMarinara thanks for the follow up! Makes sense, and the reason why I didn't start a PR on this. When planning data store next steps, it would be great to keep in mind agent custom data storage. The current storage solutions are all quite specific (lorebook semantic search, chat memories, memory recall), hence this ticket. But if there was an underlying way to store arbitrary data as part of the core engine, then you could build custom store management more easily without reinventing the wheel.
Author
Owner

@SpicyMarinara commented on GitHub (May 4, 2026):

Okay, so we removed the SQL Lite with the newest update; we no longer use DB to store things, so if you're up to doing some improvements to our memory systems and vectors, the floor is yours! Thanks!

<!-- gh-comment-id:4370189783 --> @SpicyMarinara commented on GitHub (May 4, 2026): Okay, so we removed the SQL Lite with the newest update; we no longer use DB to store things, so if you're up to doing some improvements to our memory systems and vectors, the floor is yours! Thanks!
Author
Owner

@adunato commented on GitHub (May 4, 2026):

Thanks! I'll have a look and come up with some thoughts.

<!-- gh-comment-id:4370208887 --> @adunato commented on GitHub (May 4, 2026): Thanks! I'll have a look and come up with some thoughts.
Author
Owner

@adunato commented on GitHub (May 9, 2026):

@SpicyMarinara I had some thoughts. I like the way the new storage system is simpler and consistent across use cases. I have proposed #589 as a general purpose way to save data with exposed tools and built-in embedding options for semantic search. Let me know what you think.

<!-- gh-comment-id:4411696676 --> @adunato commented on GitHub (May 9, 2026): @SpicyMarinara I had some thoughts. I like the way the new storage system is simpler and consistent across use cases. I have proposed #589 as a general purpose way to save data with exposed tools and built-in embedding options for semantic search. Let me know what you think.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Pasta-Devs/Marinara-Engine#152
No description provided.