Skip to content

Commit bb6c16d

Browse files
Move topic and entity graph storage from sqlite to json (#1767)
1 parent 9727c5b commit bb6c16d

22 files changed

+4743
-5957
lines changed

ts/packages/agents/browser/src/agent/browserActionHandler.mts

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import registerDebug from "debug";
5353

5454
import { handleInstacartAction } from "./instacart/actionHandler.mjs";
5555
import * as website from "website-memory";
56+
import { createGraphologyPersistenceManager } from "./knowledge/utils/graphologyPersistence.mjs";
5657
import { handleKnowledgeAction } from "./knowledge/actions/knowledgeActionRouter.mjs";
5758
import { ExtractKnowledgeHandler } from "./knowledge/extractKnowledgeCommand.mjs";
5859
import {
@@ -655,7 +656,6 @@ async function processBrowserAgentMessage(
655656
case "getTopicMetrics":
656657
case "getTopicTimelines":
657658
case "getViewportBasedNeighborhood":
658-
case "testMergeTopicHierarchies":
659659
case "mergeTopicHierarchies":
660660
case "discoverRelatedKnowledge":
661661
case "getTopicDetails":
@@ -792,6 +792,10 @@ async function initializeWebsiteIndex(
792792
websiteIndexes[0].path,
793793
"index",
794794
);
795+
796+
// Initialize JSON storage alongside SQLite
797+
await initializeGraphologyStorage(context, websiteIndexes[0].path);
798+
795799
debug(
796800
`Loaded website index with ${context.agentContext.websiteCollection?.messages.length || 0} websites`,
797801
);
@@ -848,6 +852,12 @@ async function initializeWebsiteIndex(
848852
sizeOnDisk: 0,
849853
};
850854

855+
// Initialize JSON storage and perform migration if needed
856+
await initializeGraphologyStorage(
857+
context,
858+
indexPath,
859+
);
860+
851861
debug(
852862
`Loaded existing website collection with ${websiteCollection.messages.length} websites from ${indexPath}`,
853863
);
@@ -891,6 +901,9 @@ async function initializeWebsiteIndex(
891901
sizeOnDisk: 0,
892902
};
893903

904+
// Initialize JSON storage for new index
905+
await initializeGraphologyStorage(context, indexPath);
906+
894907
debug(
895908
`Index will be created at ${indexPath} when first page is indexed`,
896909
);
@@ -918,6 +931,40 @@ async function initializeWebsiteIndex(
918931
}
919932
}
920933

934+
/**
935+
* Initialize Graphology storage for pure Graphology architecture
936+
*/
937+
async function initializeGraphologyStorage(
938+
context: SessionContext<BrowserActionContext>,
939+
indexPath: string,
940+
): Promise<void> {
941+
try {
942+
debug("Initializing Graphology storage");
943+
944+
// Create storage path for Graphology files
945+
const graphologyStoragePath = path.join(indexPath, "storage");
946+
947+
// Create Graphology persistence manager
948+
const persistenceManager = createGraphologyPersistenceManager(
949+
graphologyStoragePath,
950+
);
951+
952+
// Store reference in context for later use (maintaining compatibility)
953+
if (!context.agentContext.graphJsonStorage) {
954+
context.agentContext.graphJsonStorage = {
955+
manager: persistenceManager,
956+
lastEntityGraphUpdate: null,
957+
lastTopicGraphUpdate: null,
958+
};
959+
}
960+
961+
debug("Graphology storage initialization complete");
962+
} catch (error) {
963+
debug(`Error initializing Graphology storage: ${error}`);
964+
// Don't throw - this should not break the main initialization
965+
}
966+
}
967+
921968
async function getSessionFolderPath(
922969
context: SessionContext<BrowserActionContext>,
923970
) {

ts/packages/agents/browser/src/agent/browserActions.mts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export type BrowserActionContext = {
3333
tabTitleIndex?: TabTitleIndex | undefined;
3434
allowDynamicAgentDomains?: string[];
3535
websiteCollection?: website.WebsiteCollection | undefined;
36+
graphJsonStorage?: any | undefined; // GraphologyPersistenceManager - field name maintained for compatibility
3637
fuzzyMatchingModel?: TextEmbeddingModel | undefined;
3738
index: website.IndexData | undefined;
3839
viewProcess?: ChildProcess | undefined;

0 commit comments

Comments
 (0)