refactor(server): search memory through the contract in artifacts, agent runs, route proposals and onboarding (P1.5)
- Artifact Center related search lists personal and workspace memories through server.memory and finds related chat sessions in the session files (UF-034). - /api/agent/run searches the requested workspace's memory, or personal memory when no known workspace is given. - Executor briefs search only the workspace's own memory and leave out temporary memories in the query; route proposals no longer borrow a mind from the cache. - Onboarding treats any personal memory as evidence of prior use. - The service no longer creates personal.mind on a fresh install, and isFirstRun also looks for waggle.db.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
// loop's onProgress callback (Phase 3.4 — AgentRunProgressEvent).
|
||||
|
||||
import type { FastifyPluginAsync } from 'fastify';
|
||||
import { HybridSearch } from '@waggle/core';
|
||||
import { PERSONAL_SCOPE, workspaceScope } from '@waggle/memory-contract';
|
||||
import {
|
||||
runRetrievalAgentLoop,
|
||||
listShapes,
|
||||
@@ -195,30 +195,29 @@ export const agentRunRoutes: FastifyPluginAsync = async (server) => {
|
||||
};
|
||||
}
|
||||
|
||||
/** Build the HybridSearch-backed search fn for the requested workspace. */
|
||||
/**
|
||||
* Search fn over the requested workspace's memory; personal memory when no
|
||||
* known workspace is given.
|
||||
*/
|
||||
function makeSearch(workspaceId: string | undefined): RetrievalSearchFn | null {
|
||||
const personalMindDb = server.multiMind?.personal;
|
||||
if (!personalMindDb) return null;
|
||||
const embedder = server.embeddingProvider;
|
||||
if (!embedder) return null;
|
||||
const memory = server.memory;
|
||||
if (!memory) return null;
|
||||
|
||||
const targetMindDb =
|
||||
workspaceId && workspaceId !== 'personal'
|
||||
? server.agentState?.getWorkspaceMindDb?.(workspaceId) ?? personalMindDb
|
||||
: personalMindDb;
|
||||
|
||||
const hybrid = new HybridSearch(targetMindDb, embedder);
|
||||
const scope =
|
||||
workspaceId && workspaceId !== 'personal' && server.workspaceManager?.get(workspaceId)
|
||||
? workspaceScope(workspaceId)
|
||||
: PERSONAL_SCOPE;
|
||||
|
||||
return async ({ query, limit }) => {
|
||||
const hits = await hybrid.search(query, { limit: limit ?? 8 });
|
||||
const hits = await memory.search(query, { scopes: [scope], limit: limit ?? 8 });
|
||||
return {
|
||||
formattedResults:
|
||||
hits.length === 0
|
||||
? ''
|
||||
: hits
|
||||
.map(
|
||||
(s, i) =>
|
||||
`[result ${i + 1}, score ${s.finalScore.toFixed(3)}]\n${s.frame.content}`,
|
||||
(hit, i) =>
|
||||
`[result ${i + 1}, score ${hit.score.toFixed(3)}]\n${hit.text}`,
|
||||
)
|
||||
.join('\n\n---\n\n'),
|
||||
resultCount: hits.length,
|
||||
@@ -242,7 +241,7 @@ export const agentRunRoutes: FastifyPluginAsync = async (server) => {
|
||||
const search = makeSearch(workspaceId);
|
||||
if (!search) {
|
||||
return reply.status(503).send({
|
||||
error: 'multi-mind or embedding provider not initialized',
|
||||
error: 'memory not initialized',
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user