noteconnection 1.7.0 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +674 -21
- package/README.md +260 -1626
- package/dist/src/agent_workspace.contract.parity.test.js +159 -0
- package/dist/src/agent_workspace.frontend.test.js +10388 -0
- package/dist/src/agent_workspace.locale.contract.test.js +95 -0
- package/dist/src/agent_workspace.runtime.behavior.test.js +5072 -0
- package/dist/src/android.knowledgebase.picker.contract.test.js +102 -0
- package/dist/src/appimage.patchelf.test.js +113 -0
- package/dist/src/appimage.portability.test.js +156 -0
- package/dist/src/backend/FileLoader.js +18 -4
- package/dist/src/backend/FileLoader.test.js +125 -0
- package/dist/src/backend/GraphBuilder.identity.test.js +86 -0
- package/dist/src/backend/GraphBuilder.js +66 -18
- package/dist/src/backend/GraphBuilder.matching.test.js +127 -0
- package/dist/src/backend/GraphMetrics.js +0 -3
- package/dist/src/backend/ResourceIdentity.js +155 -0
- package/dist/src/backend/ResourceIdentity.test.js +113 -0
- package/dist/src/backend/algorithms/CycleDetection.js +0 -1
- package/dist/src/backend/algorithms/HybridEngine.js +0 -3
- package/dist/src/backend/algorithms/LayoutEngine.js +0 -1
- package/dist/src/backend/algorithms/StatisticalAnalyzer.js +0 -4
- package/dist/src/backend/algorithms/TopologicalSort.js +0 -2
- package/dist/src/backend/build_dag.js +0 -1
- package/dist/src/capacitor.bridge.serialization.contract.test.js +3 -0
- package/dist/src/capacitor.runtime.contract.test.js +11 -2
- package/dist/src/copy.assets.contract.test.js +130 -0
- package/dist/src/core/Graph.js +138 -42
- package/dist/src/core/Graph.test.js +74 -0
- package/dist/src/core/NoteConnection.js +2 -2
- package/dist/src/core/PathBridge.js +293 -5
- package/dist/src/core/ResourceReference.js +17 -0
- package/dist/src/desktop.godot.pack.test.js +142 -0
- package/dist/src/desktop.runtime.graph.test.js +66 -0
- package/dist/src/export/WorkspaceExportBundle.js +1174 -0
- package/dist/src/export/WorkspaceExportBundle.test.js +1541 -0
- package/dist/src/export/index.js +18 -0
- package/dist/src/export/types.js +2 -0
- package/dist/src/fixrisk.issue.verifier.contract.test.js +3 -1
- package/dist/src/foundation.ann.runtime.contract.test.js +81 -0
- package/dist/src/foundation.release.evidence.contract.test.js +524 -0
- package/dist/src/foundation.sqlite.runtime.contract.test.js +88 -0
- package/dist/src/frontend/README.md +260 -1626
- package/dist/src/frontend/agent_workspace.js +6011 -0
- package/dist/src/frontend/agent_workspace_runtime.js +4434 -0
- package/dist/src/frontend/analysis.js +31 -4
- package/dist/src/frontend/app.js +2178 -62
- package/dist/src/frontend/focus_mode_interactions.js +33 -0
- package/dist/src/frontend/godot_future_path_renderer.js +540 -0
- package/dist/src/frontend/godot_tree_interactions.js +178 -0
- package/dist/src/frontend/graph_state.mjs +105 -0
- package/dist/src/frontend/hosted_future_path_runtime.js +157 -0
- package/dist/src/frontend/i18n.mjs +186 -0
- package/dist/src/frontend/index.html +672 -268
- package/dist/src/frontend/knowledge_projection_contract.js +230 -0
- package/dist/src/frontend/knowledge_projection_store.js +214 -0
- package/dist/src/frontend/layout_gpu.js +12 -4
- package/dist/src/frontend/libs/path_core.js +158 -42
- package/dist/src/frontend/locales/en.json +753 -5
- package/dist/src/frontend/locales/zh.json +753 -5
- package/dist/src/frontend/main.mjs +60 -0
- package/dist/src/frontend/markdown_runtime.js +827 -0
- package/dist/src/frontend/mobile_budget_runtime.js +33 -0
- package/dist/src/frontend/mobile_exact_analyzer.js +393 -0
- package/dist/src/frontend/mobile_identity_contract.js +221 -0
- package/dist/src/frontend/mobile_semantic_comparator.js +264 -0
- package/dist/src/frontend/notemd.css +49 -0
- package/dist/src/frontend/notemd.html +7 -1
- package/dist/src/frontend/notemd.js +64 -0
- package/dist/src/frontend/path.html +113 -2
- package/dist/src/frontend/path_app.js +2108 -130
- package/dist/src/frontend/path_layout.mjs +143 -0
- package/dist/src/frontend/path_mermaid_utils.mjs +108 -0
- package/dist/src/frontend/path_modules_bridge.js +486 -0
- package/dist/src/frontend/path_state.mjs +118 -0
- package/dist/src/frontend/path_styles.css +146 -0
- package/dist/src/frontend/path_worker_bridge.mjs +85 -0
- package/dist/src/frontend/reader.js +393 -33
- package/dist/src/frontend/runtime_bridge.js +67 -54
- package/dist/src/frontend/runtime_bridge.mjs +279 -0
- package/dist/src/frontend/settings.js +130 -12
- package/dist/src/frontend/simulationWorker.js +1 -1
- package/dist/src/frontend/source_manager.js +297 -22
- package/dist/src/frontend/storage_provider.js +661 -71
- package/dist/src/frontend/styles.css +2814 -72
- package/dist/src/frontend/workbench_state.mjs +101 -0
- package/dist/src/frontend/workspace_panes.js +10272 -0
- package/dist/src/frontend.locale.contract.test.js +62 -0
- package/dist/src/frontend.runtime.assets.contract.test.js +81 -0
- package/dist/src/godot.sidecar.bootstrap.contract.test.js +244 -0
- package/dist/src/graph.answer.operator.contract.test.js +72 -0
- package/dist/src/index.js +6 -2
- package/dist/src/index.knowledge-root.test.js +118 -0
- package/dist/src/indexing/IndexLifecycle.js +217 -0
- package/dist/src/indexing/IndexLifecycle.test.js +73 -0
- package/dist/src/indexing/SegmentBuilder.js +64 -0
- package/dist/src/indexing/UnitBuilder.js +48 -0
- package/dist/src/indexing/types.js +2 -0
- package/dist/src/knowledge.api.contract.test.js +172 -0
- package/dist/src/knowledge_projection.contract.test.js +134 -0
- package/dist/src/knowledge_projection_store.test.js +200 -0
- package/dist/src/learning/AnswerQualityEvaluation.js +153 -0
- package/dist/src/learning/AnswerQualityEvaluation.test.js +118 -0
- package/dist/src/learning/KnowledgeLearningPlatform.js +11181 -0
- package/dist/src/learning/KnowledgeLearningPlatform.persistence.test.js +745 -0
- package/dist/src/learning/KnowledgeLearningPlatform.program-f.test.js +99 -0
- package/dist/src/learning/KnowledgeLearningPlatform.test.js +3208 -0
- package/dist/src/learning/KnowledgeWorkspaceConversationRegression.js +2998 -0
- package/dist/src/learning/KnowledgeWorkspaceConversationRegression.test.js +3936 -0
- package/dist/src/learning/MeasurementEvidenceConflicts.test.js +78 -0
- package/dist/src/learning/PublicAnswerContract.test.js +85 -0
- package/dist/src/learning/PublicEvidenceSelection.test.js +94 -0
- package/dist/src/learning/PublicMeasurementDisclosure.test.js +54 -0
- package/dist/src/learning/agentConversationExecution.js +211 -0
- package/dist/src/learning/agentConversationExecution.test.js +209 -0
- package/dist/src/learning/agentConversationSerialization.js +266 -0
- package/dist/src/learning/agentConversationSerialization.test.js +165 -0
- package/dist/src/learning/agentResponseBudget.js +179 -0
- package/dist/src/learning/agentResponseBudget.test.js +97 -0
- package/dist/src/learning/agentWorkspaceCapabilityContracts.js +65 -0
- package/dist/src/learning/answerReleaseReview.js +5260 -0
- package/dist/src/learning/answerReleaseReview.test.js +4174 -0
- package/dist/src/learning/answerTaskPlan.js +473 -0
- package/dist/src/learning/api.js +2 -0
- package/dist/src/learning/conversationComposer.js +1721 -0
- package/dist/src/learning/conversationComposer.test.js +3220 -0
- package/dist/src/learning/domains/ConversationManager.js +53 -0
- package/dist/src/learning/domains/KnowledgeIngestor.js +238 -0
- package/dist/src/learning/domains/KnowledgeQuerier.js +187 -0
- package/dist/src/learning/domains/MasteryEngine.js +387 -0
- package/dist/src/learning/domains/MemoryPolicyManager.js +408 -0
- package/dist/src/learning/domains/QualityEvaluator.js +307 -0
- package/dist/src/learning/domains/TutorRouter.js +313 -0
- package/dist/src/learning/domains/index.js +33 -0
- package/dist/src/learning/domains/types.js +7 -0
- package/dist/src/learning/errors.js +29 -0
- package/dist/src/learning/evidenceContextAssembler.js +1368 -0
- package/dist/src/learning/evidenceContextAssembler.test.js +6332 -0
- package/dist/src/learning/graphAnswerCoverage.js +37 -0
- package/dist/src/learning/graphAnswerCoverage.test.js +93 -0
- package/dist/src/learning/graphAnswerCoverageCalibration.js +59 -0
- package/dist/src/learning/graphAnswerCoverageCalibration.test.js +46 -0
- package/dist/src/learning/graphAnswerFacts.js +94 -0
- package/dist/src/learning/graphAnswerFacts.test.js +39 -0
- package/dist/src/learning/graphAnswerPlan.js +908 -0
- package/dist/src/learning/graphAnswerPlan.test.js +907 -0
- package/dist/src/learning/graphAnswerQualityCalibration.js +255 -0
- package/dist/src/learning/graphAnswerQualityCalibration.test.js +72 -0
- package/dist/src/learning/graphAnswerQualityPolicy.js +30 -0
- package/dist/src/learning/graphClaimMatcher.js +104 -0
- package/dist/src/learning/graphConditionedContext.js +109 -0
- package/dist/src/learning/graphConditionedContext.test.js +99 -0
- package/dist/src/learning/graphContextAssembler.js +860 -0
- package/dist/src/learning/graphContextAssembler.test.js +1033 -0
- package/dist/src/learning/graphExpansionPolicy.js +22 -0
- package/dist/src/learning/graphExpansionPolicy.test.js +33 -0
- package/dist/src/learning/identityMetadata.test.js +26 -0
- package/dist/src/learning/index.js +29 -0
- package/dist/src/learning/mobileAnswerProjection.js +104 -0
- package/dist/src/learning/mobileAnswerProjection.test.js +102 -0
- package/dist/src/learning/queryBackend.js +1922 -0
- package/dist/src/learning/queryBackend.test.js +976 -0
- package/dist/src/learning/ragContextPack.js +356 -0
- package/dist/src/learning/ragContextPack.test.js +311 -0
- package/dist/src/learning/ragEvidenceQuality.js +96 -0
- package/dist/src/learning/ragEvidenceQuality.test.js +29 -0
- package/dist/src/learning/ragPublicText.js +101 -0
- package/dist/src/learning/ragPublicText.test.js +57 -0
- package/dist/src/learning/ragSufficiencyJudge.js +171 -0
- package/dist/src/learning/ragSufficiencyJudge.test.js +177 -0
- package/dist/src/learning/ragSufficiencyProviderJudge.js +217 -0
- package/dist/src/learning/ragSufficiencyProviderJudge.test.js +207 -0
- package/dist/src/learning/requestNormalization.js +304 -0
- package/dist/src/learning/requestNormalization.test.js +101 -0
- package/dist/src/learning/runtimeCapability.js +4677 -0
- package/dist/src/learning/runtimeCapability.test.js +3635 -0
- package/dist/src/learning/store.js +1344 -0
- package/dist/src/learning/store.test.js +1425 -0
- package/dist/src/learning/tutorAdapter.js +2 -0
- package/dist/src/learning/types.js +2 -0
- package/dist/src/learning/vectorAccelerationAdapter.js +958 -0
- package/dist/src/learning/vectorAccelerationAdapter.test.js +412 -0
- package/dist/src/learning/workspaceHydration.js +168 -0
- package/dist/src/learning/workspaceHydration.test.js +30 -0
- package/dist/src/lfs.asset.policy.contract.test.js +153 -0
- package/dist/src/license.policy.contract.test.js +71 -0
- package/dist/src/markdown/MarkdownGateway.js +4 -0
- package/dist/src/markdown/MarkdownGateway.test.js +59 -0
- package/dist/src/memory/MemoryGovernance.js +74 -0
- package/dist/src/memory/MemoryGovernance.test.js +46 -0
- package/dist/src/memory/types.js +2 -0
- package/dist/src/mermaid.frontend.guard.contract.test.js +77 -0
- package/dist/src/middleware/SseResponseWriter.js +122 -0
- package/dist/src/middleware/SseResponseWriter.test.js +54 -0
- package/dist/src/middleware/auth.js +38 -0
- package/dist/src/middleware/auth.test.js +33 -0
- package/dist/src/middleware/body-parser.js +45 -0
- package/dist/src/middleware/cors.js +44 -0
- package/dist/src/middleware/index.js +22 -0
- package/dist/src/middleware/request-trace.js +96 -0
- package/dist/src/mobile.android.evidence.contract.test.js +146 -0
- package/dist/src/mobile.android.signing.contract.test.js +66 -0
- package/dist/src/mobile.artifact.contract.test.js +144 -0
- package/dist/src/mobile.budget.contract.test.js +90 -0
- package/dist/src/mobile.canonical-id.readiness.test.js +54 -0
- package/dist/src/mobile.graph.parity.contract.test.js +207 -0
- package/dist/src/mobile.identity.contract.test.js +66 -0
- package/dist/src/mobile.identity.corpus.manifest.test.js +72 -0
- package/dist/src/mobile.identity.corpus.test.js +40 -0
- package/dist/src/mobile.native.recovery.contract.test.js +64 -0
- package/dist/src/mobile.pipeline.test.js +11 -1
- package/dist/src/mobile.profile.contract.test.js +225 -0
- package/dist/src/mobile.semantic.parity.test.js +92 -0
- package/dist/src/mobile_exact_analyzer.test.js +113 -0
- package/dist/src/notemd/AppConfigToml.js +6 -4
- package/dist/src/notemd/ContentGenerator.js +4 -9
- package/dist/src/notemd/FileProcessor.js +4 -9
- package/dist/src/notemd/MermaidProcessor.js +400 -50
- package/dist/src/notemd/NotemdService.js +506 -26
- package/dist/src/notemd/PromptManager.js +15 -0
- package/dist/src/notemd/Translator.js +4 -9
- package/dist/src/notemd/cli/commands.js +357 -0
- package/dist/src/notemd/cli/dispatcher.js +225 -0
- package/dist/src/notemd/cli/index.js +169 -0
- package/dist/src/notemd/cli/parser.js +68 -0
- package/dist/src/notemd/cli/types.js +2 -0
- package/dist/src/notemd/constants.js +43 -0
- package/dist/src/notemd/diagram/diagramGenerationService.js +78 -0
- package/dist/src/notemd/diagram/diagramSpec.js +79 -0
- package/dist/src/notemd/diagram/diagramSpecResponseParser.js +131 -0
- package/dist/src/notemd/diagram/intent.js +95 -0
- package/dist/src/notemd/diagram/planner.js +71 -0
- package/dist/src/notemd/diagram/prompts/diagramSpecPrompt.js +42 -0
- package/dist/src/notemd/diagram/types.js +18 -0
- package/dist/src/notemd/index.js +26 -0
- package/dist/src/notemd/operations/capabilityManifest.js +23 -0
- package/dist/src/notemd/operations/cliContracts.js +17 -0
- package/dist/src/notemd/operations/configProfileCommands.js +85 -0
- package/dist/src/notemd/operations/registry.contract.test.js +95 -0
- package/dist/src/notemd/operations/registry.js +991 -0
- package/dist/src/notemd/operations/types.js +2 -0
- package/dist/src/notemd/progressReporter.js +9 -0
- package/dist/src/notemd/providerDiagnostics.js +220 -0
- package/dist/src/notemd/providerProfiles.js +42 -0
- package/dist/src/notemd/providerTemplates.js +231 -0
- package/dist/src/notemd/search/DuckDuckGoProvider.js +39 -0
- package/dist/src/notemd/search/SearchManager.js +13 -0
- package/dist/src/notemd/search/SearchProvider.js +2 -0
- package/dist/src/notemd/search/TavilyProvider.js +44 -0
- package/dist/src/notemd.agent.manifest.test.js +85 -0
- package/dist/src/notemd.api.contract.test.js +14 -1
- package/dist/src/notemd.app_config_toml.test.js +2 -1
- package/dist/src/notemd.batch.workflow.test.js +117 -0
- package/dist/src/notemd.cli.e2e.test.js +136 -0
- package/dist/src/notemd.core.test.js +51 -0
- package/dist/src/notemd.diagram.pipeline.test.js +233 -0
- package/dist/src/notemd.providerTemplates.test.js +34 -0
- package/dist/src/notemd.server.integration.test.js +262 -39
- package/dist/src/notemd.workflow.pipeline.test.js +162 -0
- package/dist/src/pathbridge.handshake.contract.test.js +45 -2
- package/dist/src/pathbridge.host-adapter.contract.test.js +133 -0
- package/dist/src/pathcore.bundle.contract.test.js +8 -0
- package/dist/src/pathmode.background.contract.test.js +69 -0
- package/dist/src/pathmode.settings.api.contract.test.js +9 -0
- package/dist/src/pkg.sidecar.contract.test.js +9 -3
- package/dist/src/platform/ExportProfile.js +86 -0
- package/dist/src/platform/MobileBudget.js +11 -0
- package/dist/src/platform/PlatformCapabilities.js +59 -0
- package/dist/src/platform/PlatformCapabilities.test.js +36 -0
- package/dist/src/platform/RenderMaterializer.js +33 -0
- package/dist/src/platform/RenderMaterializer.test.js +32 -0
- package/dist/src/query_backend.external_http.integration.test.js +410 -0
- package/dist/src/reader_renderer.js +404 -3
- package/dist/src/reader_renderer.test.js +87 -0
- package/dist/src/release.godot.mirror.contract.test.js +97 -0
- package/dist/src/resources/ResourceRegistry.js +263 -0
- package/dist/src/resources/ResourceRegistry.test.js +97 -0
- package/dist/src/resources/types.js +2 -0
- package/dist/src/routes/agentWorkspaceDiagnostics.js +173 -0
- package/dist/src/routes/index.js +19 -0
- package/dist/src/routes/knowledge.js +981 -0
- package/dist/src/routes/knowledgePayload.js +185 -0
- package/dist/src/routes/knowledgePayload.test.js +53 -0
- package/dist/src/routes/markdown.js +295 -0
- package/dist/src/routes/notemd.js +1321 -0
- package/dist/src/routes/registry.contract.test.js +133 -0
- package/dist/src/routes/registry.shadow.contract.test.js +22 -0
- package/dist/src/routes/render.js +248 -0
- package/dist/src/routes/runtimeRunbookRouteOps.js +149 -0
- package/dist/src/routes/runtimeRunbookRouteOps.test.js +194 -0
- package/dist/src/routes/settings.js +6 -0
- package/dist/src/routes/staticFiles.js +94 -0
- package/dist/src/routes/types.js +2 -0
- package/dist/src/runtime.capabilities.test.js +18 -2
- package/dist/src/runtime.transport.adapter.contract.test.js +81 -0
- package/dist/src/server.js +10342 -1325
- package/dist/src/server.migration.test.js +584 -10
- package/dist/src/server.port.fallback.contract.test.js +63 -0
- package/dist/src/session/SessionStateStore.js +81 -0
- package/dist/src/session/SessionStateStore.test.js +58 -0
- package/dist/src/session/types.js +2 -0
- package/dist/src/settings.runtime.contract.test.js +50 -0
- package/dist/src/shared/types.contract.test.js +107 -0
- package/dist/src/shared/types.js +22 -0
- package/dist/src/sidecar.build.lock.contract.test.js +201 -0
- package/dist/src/sidecar.freshness.contract.test.js +184 -0
- package/dist/src/sidecar.replacement.boundary.contract.test.js +131 -0
- package/dist/src/sidecar.supply.readiness.contract.test.js +155 -0
- package/dist/src/simulation.worker.offline.test.js +104 -0
- package/dist/src/source_manager.loadflow.test.js +46 -0
- package/dist/src/startup.layout.snapshot.contract.test.js +57 -0
- package/dist/src/storage.provider.capacitor.content.contract.test.js +4 -1
- package/dist/src/storage.provider.contract.test.js +152 -1
- package/dist/src/tauri.frontend.build.contract.test.js +68 -0
- package/dist/src/tauri.sidecar.cleanup.contract.test.js +21 -0
- package/dist/src/tauri.window.evidence.execution.test.js +68 -0
- package/dist/src/utils/RuntimePaths.js +10 -13
- package/dist/src/utils/RuntimePaths.test.js +27 -0
- package/dist/src/utils/platform.js +153 -0
- package/dist/src/windows.installer.build.test.js +109 -0
- package/dist/src/windows.installer.payload.test.js +76 -0
- package/dist/src/windows.installer.runtime.test.js +69 -0
- package/dist/src/workflows/WorkflowArtifactStore.js +96 -0
- package/dist/src/workflows/WorkflowArtifactStore.test.js +80 -0
- package/dist/src/workflows/types.js +2 -0
- package/dist/src/workspace/WorkspaceRegistry.js +135 -0
- package/dist/src/workspace/WorkspaceRegistry.test.js +29 -0
- package/dist/src/workspace/types.js +2 -0
- package/package.json +80 -15
|
@@ -0,0 +1,1922 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.LocalVectorGraphQueryBackend = exports.KeywordOnlyGraphQueryBackend = exports.LocalHybridGraphQueryBackend = void 0;
|
|
37
|
+
exports.evaluateAnnRunbookHealth = evaluateAnnRunbookHealth;
|
|
38
|
+
exports.normalizeGraphQueryBackendType = normalizeGraphQueryBackendType;
|
|
39
|
+
exports.normalizeLocalVectorAccelerationFailureMode = normalizeLocalVectorAccelerationFailureMode;
|
|
40
|
+
exports.createGraphQueryBackend = createGraphQueryBackend;
|
|
41
|
+
exports.listGraphQueryBackendCatalog = listGraphQueryBackendCatalog;
|
|
42
|
+
const crypto_1 = require("crypto");
|
|
43
|
+
const fs = __importStar(require("fs"));
|
|
44
|
+
const path = __importStar(require("path"));
|
|
45
|
+
const graphClaimMatcher_1 = require("./graphClaimMatcher");
|
|
46
|
+
function evaluateAnnRunbookHealth(params) {
|
|
47
|
+
const checks = [];
|
|
48
|
+
const threshold = params.failureThreshold ?? 3;
|
|
49
|
+
const minEffectiveness = params.minPrefilterEffectivenessRatio ?? 0.01;
|
|
50
|
+
// Check 1: Circuit state
|
|
51
|
+
const circuitHealthy = params.circuitState !== 'open';
|
|
52
|
+
checks.push({
|
|
53
|
+
name: 'circuit_state',
|
|
54
|
+
passed: circuitHealthy,
|
|
55
|
+
value: params.circuitState ?? 'unknown',
|
|
56
|
+
threshold: 'closed',
|
|
57
|
+
operator: 'eq',
|
|
58
|
+
message: circuitHealthy ? 'Circuit closed' : 'Circuit open — requests blocked',
|
|
59
|
+
});
|
|
60
|
+
// Check 2: Consecutive failures
|
|
61
|
+
const failuresHealthy = (params.consecutiveFailures ?? 0) < threshold;
|
|
62
|
+
checks.push({
|
|
63
|
+
name: 'consecutive_failures',
|
|
64
|
+
passed: failuresHealthy,
|
|
65
|
+
value: params.consecutiveFailures ?? 0,
|
|
66
|
+
threshold,
|
|
67
|
+
operator: 'lt',
|
|
68
|
+
message: failuresHealthy ? 'Within threshold' : `Exceeded threshold (${params.consecutiveFailures} >= ${threshold})`,
|
|
69
|
+
});
|
|
70
|
+
// Check 3: Prefilter effectiveness
|
|
71
|
+
const effectiveness = params.prefilterEffectivenessRatio ?? 1;
|
|
72
|
+
const prefilterHealthy = effectiveness >= minEffectiveness;
|
|
73
|
+
checks.push({
|
|
74
|
+
name: 'prefilter_effectiveness',
|
|
75
|
+
passed: prefilterHealthy,
|
|
76
|
+
value: effectiveness,
|
|
77
|
+
threshold: minEffectiveness,
|
|
78
|
+
operator: 'gte',
|
|
79
|
+
message: prefilterHealthy ? 'Effective prefilter' : 'Prefilter too narrow — may miss relevant atoms',
|
|
80
|
+
});
|
|
81
|
+
// Check 4: Representation consistency
|
|
82
|
+
const repHealthy = params.representationStatus !== 'mismatch';
|
|
83
|
+
checks.push({
|
|
84
|
+
name: 'representation_consistency',
|
|
85
|
+
passed: repHealthy || !params.representationStrictMode,
|
|
86
|
+
value: params.representationStatus ?? 'unknown',
|
|
87
|
+
threshold: 'aligned',
|
|
88
|
+
operator: 'eq',
|
|
89
|
+
message: repHealthy ? 'Aligned' : `Mismatch: ${params.representationStatus}`,
|
|
90
|
+
});
|
|
91
|
+
const failed = checks.filter(c => !c.passed);
|
|
92
|
+
const status = failed.length === 0 ? 'healthy'
|
|
93
|
+
: failed.length <= 1 && checks[0].passed ? 'degraded'
|
|
94
|
+
: 'unhealthy';
|
|
95
|
+
return {
|
|
96
|
+
status,
|
|
97
|
+
checks,
|
|
98
|
+
summary: failed.length === 0
|
|
99
|
+
? 'All ANN health checks passed.'
|
|
100
|
+
: `${failed.length}/${checks.length} checks failed: ${failed.map(c => c.name).join(', ')}.`,
|
|
101
|
+
checkedAt: new Date().toISOString(),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const GRAPH_QUERY_BACKEND_CATALOG = [
|
|
105
|
+
{
|
|
106
|
+
backend: 'local_hybrid',
|
|
107
|
+
backendId: 'local-hybrid-v1',
|
|
108
|
+
label: 'Local Hybrid',
|
|
109
|
+
aliases: ['local_hybrid', 'local-hybrid', 'hybrid'],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
backend: 'keyword_only',
|
|
113
|
+
backendId: 'keyword-only-v1',
|
|
114
|
+
label: 'Keyword Only',
|
|
115
|
+
aliases: ['keyword_only', 'keyword-only', 'keyword'],
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
backend: 'local_vector',
|
|
119
|
+
backendId: 'local-vector-v1',
|
|
120
|
+
label: 'Local Vector',
|
|
121
|
+
aliases: ['local_vector', 'local-vector', 'vector', 'semantic_vector', 'semantic-vector'],
|
|
122
|
+
},
|
|
123
|
+
];
|
|
124
|
+
const SEMANTIC_CONTENT_TOKEN_LIMIT = 180;
|
|
125
|
+
const SEMANTIC_TITLE_TOKEN_LIMIT = 24;
|
|
126
|
+
const SEMANTIC_KEYWORD_TOKEN_LIMIT = 40;
|
|
127
|
+
const SEMANTIC_QUERY_TOKEN_LIMIT = 48;
|
|
128
|
+
const SEMANTIC_CJK_NGRAM_LIMIT = 96;
|
|
129
|
+
const LOCAL_VECTOR_INDEX_SCHEMA_VERSION = 2;
|
|
130
|
+
const LOCAL_VECTOR_INDEX_BACKEND_ID = 'local-vector-v1';
|
|
131
|
+
const LOCAL_VECTOR_INDEX_SIGNATURE_VERSION = 'local-vector-index-signature-v2';
|
|
132
|
+
const LOCAL_VECTOR_ACCELERATION_ADAPTER_ID = 'local-vector-acceleration-ann-v1';
|
|
133
|
+
const LOCAL_VECTOR_REPRESENTATION_VERSION = 'local-vector-representation-v2';
|
|
134
|
+
const LOCAL_VECTOR_EMBEDDING_MODEL_ID = 'local-semantic-tfidf-unicode-v2';
|
|
135
|
+
const LOCAL_VECTOR_ANN_MIN_ATOMS = 96;
|
|
136
|
+
const LOCAL_VECTOR_ANN_TOP_QUERY_TOKENS = 8;
|
|
137
|
+
const LOCAL_VECTOR_ANN_CANDIDATE_MULTIPLIER = 28;
|
|
138
|
+
const LOCAL_VECTOR_ANN_CANDIDATE_MIN_FLOOR = 48;
|
|
139
|
+
const LOCAL_VECTOR_ANN_SIGNATURE_PREFIX_BITS = 14;
|
|
140
|
+
const LOCAL_VECTOR_ANN_SIGNATURE_SCORE_BONUS = 0.08;
|
|
141
|
+
const LOCAL_VECTOR_ANN_HASH_CACHE_SOFT_LIMIT = 50000;
|
|
142
|
+
const LOCAL_VECTOR_TOKEN_HASH_CACHE = new Map();
|
|
143
|
+
function clamp(value, minValue, maxValue) {
|
|
144
|
+
return Math.min(maxValue, Math.max(minValue, value));
|
|
145
|
+
}
|
|
146
|
+
function normalizeSemanticToken(rawValue) {
|
|
147
|
+
return String(rawValue || '')
|
|
148
|
+
.trim()
|
|
149
|
+
.toLowerCase()
|
|
150
|
+
.normalize('NFKC')
|
|
151
|
+
.replace(/[^\p{L}\p{N}]+/gu, '');
|
|
152
|
+
}
|
|
153
|
+
function stemSemanticToken(rawValue) {
|
|
154
|
+
const token = normalizeSemanticToken(rawValue);
|
|
155
|
+
if (!token) {
|
|
156
|
+
return '';
|
|
157
|
+
}
|
|
158
|
+
if (!/^[a-z0-9]+$/.test(token)) {
|
|
159
|
+
return token;
|
|
160
|
+
}
|
|
161
|
+
if (token.endsWith('ies') && token.length > 4) {
|
|
162
|
+
return `${token.slice(0, -3)}y`;
|
|
163
|
+
}
|
|
164
|
+
if (token.endsWith('ing') && token.length > 5) {
|
|
165
|
+
return token.slice(0, -3);
|
|
166
|
+
}
|
|
167
|
+
if (token.endsWith('ed') && token.length > 4) {
|
|
168
|
+
return token.slice(0, -2);
|
|
169
|
+
}
|
|
170
|
+
if (token.endsWith('es') && token.length > 4 && !token.endsWith('ses')) {
|
|
171
|
+
return token.slice(0, -2);
|
|
172
|
+
}
|
|
173
|
+
if (token.endsWith('s')
|
|
174
|
+
&& token.length > 3
|
|
175
|
+
&& !token.endsWith('ss')
|
|
176
|
+
&& !token.endsWith('is')
|
|
177
|
+
&& !token.endsWith('us')) {
|
|
178
|
+
return token.slice(0, -1);
|
|
179
|
+
}
|
|
180
|
+
return token;
|
|
181
|
+
}
|
|
182
|
+
function buildCjkSemanticNgrams(rawText, limit) {
|
|
183
|
+
if (limit <= 0) {
|
|
184
|
+
return [];
|
|
185
|
+
}
|
|
186
|
+
const segments = String(rawText || '')
|
|
187
|
+
.normalize('NFKC')
|
|
188
|
+
.match(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]+/gu) || [];
|
|
189
|
+
const tokens = [];
|
|
190
|
+
const seen = new Set();
|
|
191
|
+
for (const segment of segments) {
|
|
192
|
+
const chars = Array.from(segment);
|
|
193
|
+
if (chars.length === 1) {
|
|
194
|
+
const token = chars[0];
|
|
195
|
+
if (!seen.has(token)) {
|
|
196
|
+
seen.add(token);
|
|
197
|
+
tokens.push(token);
|
|
198
|
+
}
|
|
199
|
+
continue;
|
|
200
|
+
}
|
|
201
|
+
for (const gramSize of [2, 3]) {
|
|
202
|
+
if (chars.length < gramSize) {
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
for (let index = 0; index <= chars.length - gramSize; index += 1) {
|
|
206
|
+
const token = chars.slice(index, index + gramSize).join('');
|
|
207
|
+
if (!token || seen.has(token)) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
seen.add(token);
|
|
211
|
+
tokens.push(token);
|
|
212
|
+
if (tokens.length >= limit) {
|
|
213
|
+
return tokens;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return tokens;
|
|
219
|
+
}
|
|
220
|
+
function extractSemanticTokens(rawText, limit) {
|
|
221
|
+
if (limit <= 0) {
|
|
222
|
+
return [];
|
|
223
|
+
}
|
|
224
|
+
const tokens = String(rawText || '')
|
|
225
|
+
.normalize('NFKC')
|
|
226
|
+
.toLowerCase()
|
|
227
|
+
.match(/[\p{L}\p{N}]+(?:[_-][\p{L}\p{N}]+)*/gu) || [];
|
|
228
|
+
const collected = [];
|
|
229
|
+
const seen = new Set();
|
|
230
|
+
for (const token of tokens) {
|
|
231
|
+
const normalized = stemSemanticToken(token);
|
|
232
|
+
if (!normalized || seen.has(normalized)) {
|
|
233
|
+
continue;
|
|
234
|
+
}
|
|
235
|
+
seen.add(normalized);
|
|
236
|
+
collected.push(normalized);
|
|
237
|
+
if (collected.length >= limit) {
|
|
238
|
+
break;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (collected.length >= limit) {
|
|
242
|
+
return collected;
|
|
243
|
+
}
|
|
244
|
+
const cjkTokens = buildCjkSemanticNgrams(rawText, Math.min(limit - collected.length, SEMANTIC_CJK_NGRAM_LIMIT));
|
|
245
|
+
for (const token of cjkTokens) {
|
|
246
|
+
if (!token || seen.has(token)) {
|
|
247
|
+
continue;
|
|
248
|
+
}
|
|
249
|
+
seen.add(token);
|
|
250
|
+
collected.push(token);
|
|
251
|
+
if (collected.length >= limit) {
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return collected;
|
|
256
|
+
}
|
|
257
|
+
function uniqueTokens(tokens) {
|
|
258
|
+
const unique = [];
|
|
259
|
+
const seen = new Set();
|
|
260
|
+
tokens.forEach((token) => {
|
|
261
|
+
if (!token || seen.has(token)) {
|
|
262
|
+
return;
|
|
263
|
+
}
|
|
264
|
+
seen.add(token);
|
|
265
|
+
unique.push(token);
|
|
266
|
+
});
|
|
267
|
+
return unique;
|
|
268
|
+
}
|
|
269
|
+
function uniqueNormalizedStrings(values) {
|
|
270
|
+
const unique = [];
|
|
271
|
+
const seen = new Set();
|
|
272
|
+
values.forEach((value) => {
|
|
273
|
+
const normalized = String(value || '')
|
|
274
|
+
.normalize('NFKC')
|
|
275
|
+
.toLowerCase()
|
|
276
|
+
.replace(/\s+/g, ' ')
|
|
277
|
+
.trim();
|
|
278
|
+
if (!normalized || seen.has(normalized)) {
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
seen.add(normalized);
|
|
282
|
+
unique.push(normalized);
|
|
283
|
+
});
|
|
284
|
+
return unique;
|
|
285
|
+
}
|
|
286
|
+
function buildQueryTextVariants(context) {
|
|
287
|
+
return uniqueNormalizedStrings([
|
|
288
|
+
context.query,
|
|
289
|
+
...(Array.isArray(context.queryVariants) ? context.queryVariants : []),
|
|
290
|
+
]);
|
|
291
|
+
}
|
|
292
|
+
function buildAtomSemanticTokens(atom) {
|
|
293
|
+
const keywordTokens = uniqueTokens((atom.keywords || [])
|
|
294
|
+
.map((keyword) => stemSemanticToken(keyword))
|
|
295
|
+
.filter((token) => token.length > 0)
|
|
296
|
+
.slice(0, SEMANTIC_KEYWORD_TOKEN_LIMIT));
|
|
297
|
+
const titleTokens = extractSemanticTokens(atom.title, SEMANTIC_TITLE_TOKEN_LIMIT);
|
|
298
|
+
const contentTokens = extractSemanticTokens(atom.content, SEMANTIC_CONTENT_TOKEN_LIMIT);
|
|
299
|
+
const conceptTokens = (0, graphClaimMatcher_1.semanticFeatures)(`${atom.title} ${atom.content}`)
|
|
300
|
+
.filter((feature) => feature.startsWith('concept:'));
|
|
301
|
+
return uniqueTokens([...keywordTokens, ...titleTokens, ...contentTokens, ...conceptTokens]);
|
|
302
|
+
}
|
|
303
|
+
function buildQuerySemanticTokens(context) {
|
|
304
|
+
const directTokens = uniqueTokens((context.queryTokens || [])
|
|
305
|
+
.map((token) => stemSemanticToken(token))
|
|
306
|
+
.filter((token) => token.length > 0));
|
|
307
|
+
const variantTokens = buildQueryTextVariants(context).flatMap((variant) => (extractSemanticTokens(variant, SEMANTIC_QUERY_TOKEN_LIMIT)));
|
|
308
|
+
const fallbackTokens = extractSemanticTokens(context.query, SEMANTIC_QUERY_TOKEN_LIMIT);
|
|
309
|
+
const conceptTokens = (0, graphClaimMatcher_1.semanticFeatures)(buildQueryTextVariants(context).join(' '))
|
|
310
|
+
.filter((feature) => feature.startsWith('concept:'));
|
|
311
|
+
return uniqueTokens([...directTokens, ...variantTokens, ...fallbackTokens, ...conceptTokens]).slice(0, SEMANTIC_QUERY_TOKEN_LIMIT);
|
|
312
|
+
}
|
|
313
|
+
function computeJaccard(left, right) {
|
|
314
|
+
if (!left.length || !right.length) {
|
|
315
|
+
return 0;
|
|
316
|
+
}
|
|
317
|
+
const leftSet = new Set(left);
|
|
318
|
+
const rightSet = new Set(right);
|
|
319
|
+
let intersection = 0;
|
|
320
|
+
leftSet.forEach((token) => {
|
|
321
|
+
if (rightSet.has(token)) {
|
|
322
|
+
intersection += 1;
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
const union = leftSet.size + rightSet.size - intersection;
|
|
326
|
+
if (union <= 0) {
|
|
327
|
+
return 0;
|
|
328
|
+
}
|
|
329
|
+
return intersection / union;
|
|
330
|
+
}
|
|
331
|
+
function classifyGraphQueryIntent(query) {
|
|
332
|
+
const normalized = String(query || '').trim().toLowerCase();
|
|
333
|
+
if (!normalized) {
|
|
334
|
+
return 'generic';
|
|
335
|
+
}
|
|
336
|
+
if (normalized.includes('compare')
|
|
337
|
+
|| normalized.includes('difference')
|
|
338
|
+
|| normalized.includes('vs')
|
|
339
|
+
|| normalized.includes('对比')
|
|
340
|
+
|| normalized.includes('比较')
|
|
341
|
+
|| normalized.includes('区别')
|
|
342
|
+
|| normalized.includes('差异')) {
|
|
343
|
+
return 'compare';
|
|
344
|
+
}
|
|
345
|
+
if (normalized.includes('how to')
|
|
346
|
+
|| normalized.includes('how do')
|
|
347
|
+
|| normalized.includes('steps')
|
|
348
|
+
|| normalized.includes('plan')
|
|
349
|
+
|| normalized.includes('如何')
|
|
350
|
+
|| normalized.includes('怎么')
|
|
351
|
+
|| normalized.includes('步骤')
|
|
352
|
+
|| normalized.includes('方案')) {
|
|
353
|
+
return 'how_to';
|
|
354
|
+
}
|
|
355
|
+
if (normalized.includes('what is')
|
|
356
|
+
|| normalized.includes('why')
|
|
357
|
+
|| normalized.includes('explain')
|
|
358
|
+
|| normalized.includes('什么是')
|
|
359
|
+
|| normalized.includes('为什么')
|
|
360
|
+
|| normalized.includes('解释')) {
|
|
361
|
+
return 'explain';
|
|
362
|
+
}
|
|
363
|
+
return 'generic';
|
|
364
|
+
}
|
|
365
|
+
function buildAtomAnchorTokens(atom) {
|
|
366
|
+
return uniqueTokens([
|
|
367
|
+
...extractSemanticTokens(atom.title, Math.max(SEMANTIC_TITLE_TOKEN_LIMIT, 10)),
|
|
368
|
+
...extractSemanticTokens(atom.sourcePath, 10),
|
|
369
|
+
...extractSemanticTokens(atom.documentId, 6),
|
|
370
|
+
]);
|
|
371
|
+
}
|
|
372
|
+
function inferGraphAnchorAtomIds(context, querySemanticTokens) {
|
|
373
|
+
const queryVariants = buildQueryTextVariants(context);
|
|
374
|
+
const rankedAnchors = context.atoms
|
|
375
|
+
.map((atom, index) => {
|
|
376
|
+
const titleLower = String(atom.title || '').trim().toLowerCase();
|
|
377
|
+
const directMatchScore = titleLower && queryVariants.some((variant) => variant.includes(titleLower))
|
|
378
|
+
? 1
|
|
379
|
+
: 0;
|
|
380
|
+
const anchorTokenOverlap = computeJaccard(querySemanticTokens, buildAtomAnchorTokens(atom));
|
|
381
|
+
const keywordOverlap = computeJaccard(querySemanticTokens, uniqueTokens((atom.keywords || []).map((keyword) => stemSemanticToken(keyword)).filter(Boolean)));
|
|
382
|
+
const score = Number((directMatchScore
|
|
383
|
+
+ anchorTokenOverlap
|
|
384
|
+
+ (keywordOverlap * 0.35)).toFixed(6));
|
|
385
|
+
return {
|
|
386
|
+
atomId: atom.id,
|
|
387
|
+
score,
|
|
388
|
+
index,
|
|
389
|
+
};
|
|
390
|
+
})
|
|
391
|
+
.filter((entry) => entry.score > 0)
|
|
392
|
+
.sort((left, right) => (right.score - left.score
|
|
393
|
+
|| left.index - right.index));
|
|
394
|
+
if (rankedAnchors.length <= 0) {
|
|
395
|
+
return new Set();
|
|
396
|
+
}
|
|
397
|
+
const topScore = rankedAnchors[0].score;
|
|
398
|
+
return new Set(rankedAnchors
|
|
399
|
+
.filter((entry, index) => index < 3 && entry.score >= Math.max(0.2, topScore - 0.08))
|
|
400
|
+
.map((entry) => entry.atomId));
|
|
401
|
+
}
|
|
402
|
+
function buildGraphAdjacency(activeEdges) {
|
|
403
|
+
const outgoingByAtomId = new Map();
|
|
404
|
+
const incomingByAtomId = new Map();
|
|
405
|
+
const undirectedNeighborsByAtomId = new Map();
|
|
406
|
+
const degreeByAtomId = new Map();
|
|
407
|
+
const incidentRelationKindsByAtomId = new Map();
|
|
408
|
+
activeEdges.forEach((edge) => {
|
|
409
|
+
const confidence = clamp(Number(edge.confidence || 0), 0, 1);
|
|
410
|
+
const outgoing = outgoingByAtomId.get(edge.sourceAtomId) || [];
|
|
411
|
+
outgoing.push({
|
|
412
|
+
to: edge.targetAtomId,
|
|
413
|
+
relationKind: edge.relationKind,
|
|
414
|
+
confidence,
|
|
415
|
+
});
|
|
416
|
+
outgoingByAtomId.set(edge.sourceAtomId, outgoing);
|
|
417
|
+
const incoming = incomingByAtomId.get(edge.targetAtomId) || [];
|
|
418
|
+
incoming.push({
|
|
419
|
+
to: edge.sourceAtomId,
|
|
420
|
+
relationKind: edge.relationKind,
|
|
421
|
+
confidence,
|
|
422
|
+
});
|
|
423
|
+
incomingByAtomId.set(edge.targetAtomId, incoming);
|
|
424
|
+
const sourceUndirected = undirectedNeighborsByAtomId.get(edge.sourceAtomId) || [];
|
|
425
|
+
sourceUndirected.push(edge.targetAtomId);
|
|
426
|
+
undirectedNeighborsByAtomId.set(edge.sourceAtomId, sourceUndirected);
|
|
427
|
+
const targetUndirected = undirectedNeighborsByAtomId.get(edge.targetAtomId) || [];
|
|
428
|
+
targetUndirected.push(edge.sourceAtomId);
|
|
429
|
+
undirectedNeighborsByAtomId.set(edge.targetAtomId, targetUndirected);
|
|
430
|
+
degreeByAtomId.set(edge.sourceAtomId, (degreeByAtomId.get(edge.sourceAtomId) || 0) + 1);
|
|
431
|
+
degreeByAtomId.set(edge.targetAtomId, (degreeByAtomId.get(edge.targetAtomId) || 0) + 1);
|
|
432
|
+
const sourceKinds = incidentRelationKindsByAtomId.get(edge.sourceAtomId) || new Set();
|
|
433
|
+
sourceKinds.add(edge.relationKind);
|
|
434
|
+
incidentRelationKindsByAtomId.set(edge.sourceAtomId, sourceKinds);
|
|
435
|
+
const targetKinds = incidentRelationKindsByAtomId.get(edge.targetAtomId) || new Set();
|
|
436
|
+
targetKinds.add(edge.relationKind);
|
|
437
|
+
incidentRelationKindsByAtomId.set(edge.targetAtomId, targetKinds);
|
|
438
|
+
});
|
|
439
|
+
return {
|
|
440
|
+
outgoingByAtomId,
|
|
441
|
+
incomingByAtomId,
|
|
442
|
+
undirectedNeighborsByAtomId,
|
|
443
|
+
degreeByAtomId,
|
|
444
|
+
incidentRelationKindsByAtomId,
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
function buildUndirectedDistanceSignals(anchorAtomIds, undirectedNeighborsByAtomId, maxDepth) {
|
|
448
|
+
const distances = new Map();
|
|
449
|
+
const queue = [];
|
|
450
|
+
anchorAtomIds.forEach((anchorAtomId) => {
|
|
451
|
+
distances.set(anchorAtomId, 0);
|
|
452
|
+
queue.push({ atomId: anchorAtomId, distance: 0 });
|
|
453
|
+
});
|
|
454
|
+
while (queue.length > 0) {
|
|
455
|
+
const current = queue.shift();
|
|
456
|
+
if (!current) {
|
|
457
|
+
continue;
|
|
458
|
+
}
|
|
459
|
+
if (current.distance >= maxDepth) {
|
|
460
|
+
continue;
|
|
461
|
+
}
|
|
462
|
+
const neighbors = undirectedNeighborsByAtomId.get(current.atomId) || [];
|
|
463
|
+
neighbors.forEach((neighborAtomId) => {
|
|
464
|
+
const nextDistance = current.distance + 1;
|
|
465
|
+
const existingDistance = distances.get(neighborAtomId);
|
|
466
|
+
if (typeof existingDistance === 'number' && existingDistance <= nextDistance) {
|
|
467
|
+
return;
|
|
468
|
+
}
|
|
469
|
+
distances.set(neighborAtomId, nextDistance);
|
|
470
|
+
queue.push({
|
|
471
|
+
atomId: neighborAtomId,
|
|
472
|
+
distance: nextDistance,
|
|
473
|
+
});
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
return distances;
|
|
477
|
+
}
|
|
478
|
+
function shouldReplaceDirectedPathSignal(current, next) {
|
|
479
|
+
if (!current) {
|
|
480
|
+
return true;
|
|
481
|
+
}
|
|
482
|
+
if (next.distance < current.distance) {
|
|
483
|
+
return true;
|
|
484
|
+
}
|
|
485
|
+
return next.distance === current.distance && next.averageConfidence > current.averageConfidence;
|
|
486
|
+
}
|
|
487
|
+
function buildDirectedPathSignals(anchorAtomIds, adjacencyByAtomId, maxDepth) {
|
|
488
|
+
const signals = new Map();
|
|
489
|
+
const queue = [];
|
|
490
|
+
anchorAtomIds.forEach((anchorAtomId) => {
|
|
491
|
+
signals.set(anchorAtomId, {
|
|
492
|
+
distance: 0,
|
|
493
|
+
averageConfidence: 1,
|
|
494
|
+
relationKinds: [],
|
|
495
|
+
});
|
|
496
|
+
queue.push({
|
|
497
|
+
atomId: anchorAtomId,
|
|
498
|
+
distance: 0,
|
|
499
|
+
confidenceSum: 0,
|
|
500
|
+
relationKinds: [],
|
|
501
|
+
});
|
|
502
|
+
});
|
|
503
|
+
while (queue.length > 0) {
|
|
504
|
+
const current = queue.shift();
|
|
505
|
+
if (!current) {
|
|
506
|
+
continue;
|
|
507
|
+
}
|
|
508
|
+
if (current.distance >= maxDepth) {
|
|
509
|
+
continue;
|
|
510
|
+
}
|
|
511
|
+
const neighbors = adjacencyByAtomId.get(current.atomId) || [];
|
|
512
|
+
neighbors.forEach((neighbor) => {
|
|
513
|
+
const nextDistance = current.distance + 1;
|
|
514
|
+
const nextConfidenceSum = current.confidenceSum + clamp(Number(neighbor.confidence || 0), 0, 1);
|
|
515
|
+
const nextSignal = {
|
|
516
|
+
distance: nextDistance,
|
|
517
|
+
averageConfidence: Number((nextConfidenceSum / nextDistance).toFixed(4)),
|
|
518
|
+
relationKinds: current.relationKinds.includes(neighbor.relationKind)
|
|
519
|
+
? current.relationKinds
|
|
520
|
+
: [...current.relationKinds, neighbor.relationKind],
|
|
521
|
+
};
|
|
522
|
+
const currentSignal = signals.get(neighbor.to);
|
|
523
|
+
if (!shouldReplaceDirectedPathSignal(currentSignal, nextSignal)) {
|
|
524
|
+
return;
|
|
525
|
+
}
|
|
526
|
+
signals.set(neighbor.to, nextSignal);
|
|
527
|
+
queue.push({
|
|
528
|
+
atomId: neighbor.to,
|
|
529
|
+
distance: nextDistance,
|
|
530
|
+
confidenceSum: nextConfidenceSum,
|
|
531
|
+
relationKinds: nextSignal.relationKinds,
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
}
|
|
535
|
+
return signals;
|
|
536
|
+
}
|
|
537
|
+
function buildGraphFeatureIndex(context, querySemanticTokens) {
|
|
538
|
+
const queryIntent = classifyGraphQueryIntent(context.query);
|
|
539
|
+
const anchorAtomIds = inferGraphAnchorAtomIds(context, querySemanticTokens);
|
|
540
|
+
const { outgoingByAtomId, incomingByAtomId, undirectedNeighborsByAtomId, degreeByAtomId, incidentRelationKindsByAtomId, } = buildGraphAdjacency(context.activeEdges);
|
|
541
|
+
const maxDegree = Array.from(degreeByAtomId.values()).reduce((maxValue, degree) => Math.max(maxValue, degree), 0);
|
|
542
|
+
return {
|
|
543
|
+
queryIntent,
|
|
544
|
+
anchorAtomIds,
|
|
545
|
+
degreeByAtomId,
|
|
546
|
+
maxDegree,
|
|
547
|
+
incidentRelationKindsByAtomId,
|
|
548
|
+
undirectedDistanceByAtomId: buildUndirectedDistanceSignals(anchorAtomIds, undirectedNeighborsByAtomId, 4),
|
|
549
|
+
pathToAnchorByAtomId: buildDirectedPathSignals(anchorAtomIds, incomingByAtomId, 4),
|
|
550
|
+
pathFromAnchorByAtomId: buildDirectedPathSignals(anchorAtomIds, outgoingByAtomId, 4),
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
function computeAnchorDistanceBonus(atomId, graphFeatureIndex) {
|
|
554
|
+
const distance = graphFeatureIndex.undirectedDistanceByAtomId.get(atomId);
|
|
555
|
+
if (typeof distance !== 'number') {
|
|
556
|
+
return 0;
|
|
557
|
+
}
|
|
558
|
+
if (distance <= 0) {
|
|
559
|
+
return graphFeatureIndex.queryIntent === 'compare' ? 0.22 : 0.3;
|
|
560
|
+
}
|
|
561
|
+
if (distance === 1) {
|
|
562
|
+
return 0.18;
|
|
563
|
+
}
|
|
564
|
+
if (distance === 2) {
|
|
565
|
+
return 0.1;
|
|
566
|
+
}
|
|
567
|
+
if (distance === 3) {
|
|
568
|
+
return 0.05;
|
|
569
|
+
}
|
|
570
|
+
return 0;
|
|
571
|
+
}
|
|
572
|
+
function computeDirectedPathBonus(signal, intent, direction) {
|
|
573
|
+
if (!signal || signal.distance <= 0) {
|
|
574
|
+
return 0;
|
|
575
|
+
}
|
|
576
|
+
const baseBonus = signal.distance === 1
|
|
577
|
+
? 0.14
|
|
578
|
+
: signal.distance === 2
|
|
579
|
+
? 0.09
|
|
580
|
+
: 0.05;
|
|
581
|
+
const confidenceBonus = clamp(signal.averageConfidence, 0, 1) * 0.12;
|
|
582
|
+
let relationBonus = 0;
|
|
583
|
+
if (signal.relationKinds.includes('prerequisite') && direction === 'to_anchor' && intent !== 'compare') {
|
|
584
|
+
relationBonus += intent === 'how_to' ? 0.12 : 0.07;
|
|
585
|
+
}
|
|
586
|
+
if (signal.relationKinds.includes('sequence') && direction === 'from_anchor' && intent === 'how_to') {
|
|
587
|
+
relationBonus += 0.08;
|
|
588
|
+
}
|
|
589
|
+
if (signal.relationKinds.includes('application') && direction === 'from_anchor' && intent === 'how_to') {
|
|
590
|
+
relationBonus += 0.06;
|
|
591
|
+
}
|
|
592
|
+
const compareBranchSignalPresent = signal.relationKinds.includes('contrast') || signal.relationKinds.includes('analogy');
|
|
593
|
+
if (compareBranchSignalPresent && intent === 'compare') {
|
|
594
|
+
relationBonus += signal.distance === 1 ? 0.32 : 0.18;
|
|
595
|
+
}
|
|
596
|
+
const maxBonus = compareBranchSignalPresent && intent === 'compare' ? 0.6 : 0.4;
|
|
597
|
+
return Number(clamp(baseBonus + confidenceBonus + relationBonus, 0, maxBonus).toFixed(6));
|
|
598
|
+
}
|
|
599
|
+
function computeRelationIntentBonus(atomId, graphFeatureIndex) {
|
|
600
|
+
const relationKinds = graphFeatureIndex.incidentRelationKindsByAtomId.get(atomId);
|
|
601
|
+
if (!relationKinds || relationKinds.size <= 0) {
|
|
602
|
+
return 0;
|
|
603
|
+
}
|
|
604
|
+
let bonus = 0;
|
|
605
|
+
if (graphFeatureIndex.queryIntent === 'compare') {
|
|
606
|
+
if (relationKinds.has('contrast'))
|
|
607
|
+
bonus += 0.24;
|
|
608
|
+
if (relationKinds.has('analogy'))
|
|
609
|
+
bonus += 0.16;
|
|
610
|
+
if (relationKinds.has('reference'))
|
|
611
|
+
bonus += 0.02;
|
|
612
|
+
}
|
|
613
|
+
else if (graphFeatureIndex.queryIntent === 'how_to') {
|
|
614
|
+
if (relationKinds.has('prerequisite'))
|
|
615
|
+
bonus += 0.1;
|
|
616
|
+
if (relationKinds.has('sequence'))
|
|
617
|
+
bonus += 0.08;
|
|
618
|
+
if (relationKinds.has('application'))
|
|
619
|
+
bonus += 0.08;
|
|
620
|
+
if (relationKinds.has('causal'))
|
|
621
|
+
bonus += 0.04;
|
|
622
|
+
}
|
|
623
|
+
else if (graphFeatureIndex.queryIntent === 'explain') {
|
|
624
|
+
if (relationKinds.has('causal'))
|
|
625
|
+
bonus += 0.1;
|
|
626
|
+
if (relationKinds.has('reference'))
|
|
627
|
+
bonus += 0.06;
|
|
628
|
+
if (relationKinds.has('prerequisite'))
|
|
629
|
+
bonus += 0.05;
|
|
630
|
+
}
|
|
631
|
+
else {
|
|
632
|
+
if (relationKinds.has('reference'))
|
|
633
|
+
bonus += 0.04;
|
|
634
|
+
if (relationKinds.has('causal'))
|
|
635
|
+
bonus += 0.04;
|
|
636
|
+
}
|
|
637
|
+
return Number(clamp(bonus, 0, 0.18).toFixed(6));
|
|
638
|
+
}
|
|
639
|
+
function computeTemporalValidityBonus(context, atomId) {
|
|
640
|
+
const temporalSignal = context.atomTemporalValidity && typeof context.atomTemporalValidity === 'object'
|
|
641
|
+
? context.atomTemporalValidity[atomId]
|
|
642
|
+
: undefined;
|
|
643
|
+
if (!temporalSignal) {
|
|
644
|
+
return 0;
|
|
645
|
+
}
|
|
646
|
+
if (temporalSignal.isValid === false) {
|
|
647
|
+
return -Number((0.18 + Math.min(temporalSignal.reasonCount, 3) * 0.02).toFixed(6));
|
|
648
|
+
}
|
|
649
|
+
return 0;
|
|
650
|
+
}
|
|
651
|
+
function computeCompareBranchBonus(atomId, graphFeatureIndex) {
|
|
652
|
+
if (graphFeatureIndex.queryIntent !== 'compare') {
|
|
653
|
+
return 0;
|
|
654
|
+
}
|
|
655
|
+
const toAnchorSignal = graphFeatureIndex.pathToAnchorByAtomId.get(atomId);
|
|
656
|
+
const fromAnchorSignal = graphFeatureIndex.pathFromAnchorByAtomId.get(atomId);
|
|
657
|
+
const directContrastToAnchor = Boolean(toAnchorSignal
|
|
658
|
+
&& toAnchorSignal.distance === 1
|
|
659
|
+
&& (toAnchorSignal.relationKinds.includes('contrast') || toAnchorSignal.relationKinds.includes('analogy')));
|
|
660
|
+
const directContrastFromAnchor = Boolean(fromAnchorSignal
|
|
661
|
+
&& fromAnchorSignal.distance === 1
|
|
662
|
+
&& (fromAnchorSignal.relationKinds.includes('contrast') || fromAnchorSignal.relationKinds.includes('analogy')));
|
|
663
|
+
if (directContrastToAnchor || directContrastFromAnchor) {
|
|
664
|
+
return 0.24;
|
|
665
|
+
}
|
|
666
|
+
return 0;
|
|
667
|
+
}
|
|
668
|
+
function computeHubPenalty(atomId, graphFeatureIndex) {
|
|
669
|
+
if (graphFeatureIndex.maxDegree <= 0) {
|
|
670
|
+
return 0;
|
|
671
|
+
}
|
|
672
|
+
if (graphFeatureIndex.undirectedDistanceByAtomId.has(atomId)) {
|
|
673
|
+
return 0;
|
|
674
|
+
}
|
|
675
|
+
const degree = graphFeatureIndex.degreeByAtomId.get(atomId) || 0;
|
|
676
|
+
const normalizedDegree = degree / graphFeatureIndex.maxDegree;
|
|
677
|
+
if (normalizedDegree <= 0.7) {
|
|
678
|
+
return 0;
|
|
679
|
+
}
|
|
680
|
+
return Number(clamp((normalizedDegree - 0.7) * 0.25, 0, 0.12).toFixed(6));
|
|
681
|
+
}
|
|
682
|
+
function computeGraphFeatureScore(context, atomId, graphFeatureIndex) {
|
|
683
|
+
if (graphFeatureIndex.anchorAtomIds.size <= 0) {
|
|
684
|
+
return 0;
|
|
685
|
+
}
|
|
686
|
+
const anchorDistanceBonus = computeAnchorDistanceBonus(atomId, graphFeatureIndex);
|
|
687
|
+
const pathToAnchorBonus = computeDirectedPathBonus(graphFeatureIndex.pathToAnchorByAtomId.get(atomId), graphFeatureIndex.queryIntent, 'to_anchor');
|
|
688
|
+
const pathFromAnchorBonus = computeDirectedPathBonus(graphFeatureIndex.pathFromAnchorByAtomId.get(atomId), graphFeatureIndex.queryIntent, 'from_anchor');
|
|
689
|
+
const relationIntentBonus = computeRelationIntentBonus(atomId, graphFeatureIndex);
|
|
690
|
+
const temporalValidityBonus = computeTemporalValidityBonus(context, atomId);
|
|
691
|
+
const compareBranchBonus = computeCompareBranchBonus(atomId, graphFeatureIndex);
|
|
692
|
+
const hubPenalty = computeHubPenalty(atomId, graphFeatureIndex);
|
|
693
|
+
return Number((anchorDistanceBonus
|
|
694
|
+
+ pathToAnchorBonus
|
|
695
|
+
+ pathFromAnchorBonus
|
|
696
|
+
+ relationIntentBonus
|
|
697
|
+
+ temporalValidityBonus
|
|
698
|
+
+ compareBranchBonus
|
|
699
|
+
- hubPenalty).toFixed(6));
|
|
700
|
+
}
|
|
701
|
+
function buildTokenFrequency(tokens) {
|
|
702
|
+
const frequency = new Map();
|
|
703
|
+
tokens.forEach((token) => {
|
|
704
|
+
if (!token) {
|
|
705
|
+
return;
|
|
706
|
+
}
|
|
707
|
+
frequency.set(token, (frequency.get(token) || 0) + 1);
|
|
708
|
+
});
|
|
709
|
+
return frequency;
|
|
710
|
+
}
|
|
711
|
+
function buildTfIdfWeights(frequency, docFrequency, totalDocs) {
|
|
712
|
+
const weights = new Map();
|
|
713
|
+
const maxTermCount = Math.max(1, ...Array.from(frequency.values()).map((value) => Math.max(0, Math.floor(Number(value) || 0))));
|
|
714
|
+
frequency.forEach((count, token) => {
|
|
715
|
+
const tf = Math.max(0, Math.floor(Number(count) || 0)) / maxTermCount;
|
|
716
|
+
const df = Math.max(1, Math.floor(Number(docFrequency.get(token) || 0)));
|
|
717
|
+
const idf = Math.log((1 + totalDocs) / (1 + df)) + 1;
|
|
718
|
+
weights.set(token, Number((tf * idf).toFixed(8)));
|
|
719
|
+
});
|
|
720
|
+
return weights;
|
|
721
|
+
}
|
|
722
|
+
function computeCosineSimilarity(left, right) {
|
|
723
|
+
if (left.size <= 0 || right.size <= 0) {
|
|
724
|
+
return 0;
|
|
725
|
+
}
|
|
726
|
+
let dot = 0;
|
|
727
|
+
let leftNorm = 0;
|
|
728
|
+
let rightNorm = 0;
|
|
729
|
+
left.forEach((weight, token) => {
|
|
730
|
+
const rightWeight = right.get(token) || 0;
|
|
731
|
+
dot += weight * rightWeight;
|
|
732
|
+
leftNorm += weight * weight;
|
|
733
|
+
});
|
|
734
|
+
right.forEach((weight) => {
|
|
735
|
+
rightNorm += weight * weight;
|
|
736
|
+
});
|
|
737
|
+
const denominator = Math.sqrt(leftNorm) * Math.sqrt(rightNorm);
|
|
738
|
+
if (!Number.isFinite(denominator) || denominator <= 0) {
|
|
739
|
+
return 0;
|
|
740
|
+
}
|
|
741
|
+
return dot / denominator;
|
|
742
|
+
}
|
|
743
|
+
function normalizeVectorIndexPath(rawValue) {
|
|
744
|
+
const trimmed = String(rawValue || '').trim();
|
|
745
|
+
if (!trimmed) {
|
|
746
|
+
return undefined;
|
|
747
|
+
}
|
|
748
|
+
return path.resolve(trimmed);
|
|
749
|
+
}
|
|
750
|
+
function toSerializableWeightEntries(weights) {
|
|
751
|
+
const entries = [];
|
|
752
|
+
weights.forEach((weight, token) => {
|
|
753
|
+
if (!token) {
|
|
754
|
+
return;
|
|
755
|
+
}
|
|
756
|
+
const numericWeight = Number(weight);
|
|
757
|
+
if (!Number.isFinite(numericWeight) || numericWeight <= 0) {
|
|
758
|
+
return;
|
|
759
|
+
}
|
|
760
|
+
entries.push([token, Number(numericWeight.toFixed(8))]);
|
|
761
|
+
});
|
|
762
|
+
entries.sort((left, right) => left[0].localeCompare(right[0]));
|
|
763
|
+
return entries;
|
|
764
|
+
}
|
|
765
|
+
function toWeightMap(entries) {
|
|
766
|
+
const weightMap = new Map();
|
|
767
|
+
if (!Array.isArray(entries)) {
|
|
768
|
+
return weightMap;
|
|
769
|
+
}
|
|
770
|
+
entries.forEach((entry) => {
|
|
771
|
+
if (!Array.isArray(entry) || entry.length < 2) {
|
|
772
|
+
return;
|
|
773
|
+
}
|
|
774
|
+
const token = String(entry[0] || '').trim().toLowerCase();
|
|
775
|
+
const weight = Number(entry[1]);
|
|
776
|
+
if (!token || !Number.isFinite(weight) || weight <= 0) {
|
|
777
|
+
return;
|
|
778
|
+
}
|
|
779
|
+
weightMap.set(token, Number(weight.toFixed(8)));
|
|
780
|
+
});
|
|
781
|
+
return weightMap;
|
|
782
|
+
}
|
|
783
|
+
function computeLocalVectorSignature(atoms) {
|
|
784
|
+
const hash = (0, crypto_1.createHash)('sha256');
|
|
785
|
+
hash.update(LOCAL_VECTOR_INDEX_SIGNATURE_VERSION);
|
|
786
|
+
const sortedAtoms = [...atoms].sort((left, right) => left.id.localeCompare(right.id));
|
|
787
|
+
sortedAtoms.forEach((atom) => {
|
|
788
|
+
const sourceHash = String(atom.metadata?.sourceHash || '').trim();
|
|
789
|
+
const version = Number(atom.metadata?.version || 0);
|
|
790
|
+
hash.update(atom.id);
|
|
791
|
+
hash.update('\u0000');
|
|
792
|
+
hash.update(String(atom.updatedAt || ''));
|
|
793
|
+
hash.update('\u0000');
|
|
794
|
+
hash.update(sourceHash);
|
|
795
|
+
hash.update('\u0000');
|
|
796
|
+
hash.update(String(Number.isFinite(version) ? version : 0));
|
|
797
|
+
hash.update('\u0000');
|
|
798
|
+
if (!sourceHash) {
|
|
799
|
+
hash.update(String(atom.title || ''));
|
|
800
|
+
hash.update('\u0000');
|
|
801
|
+
hash.update(String(atom.content || ''));
|
|
802
|
+
hash.update('\u0000');
|
|
803
|
+
hash.update((atom.keywords || []).join('|'));
|
|
804
|
+
}
|
|
805
|
+
hash.update('\u0001');
|
|
806
|
+
});
|
|
807
|
+
return hash.digest('hex');
|
|
808
|
+
}
|
|
809
|
+
function getLocalVectorTokenHash64(token) {
|
|
810
|
+
const normalizedToken = String(token || '').trim().toLowerCase();
|
|
811
|
+
if (!normalizedToken) {
|
|
812
|
+
return 0n;
|
|
813
|
+
}
|
|
814
|
+
const cached = LOCAL_VECTOR_TOKEN_HASH_CACHE.get(normalizedToken);
|
|
815
|
+
if (typeof cached !== 'undefined') {
|
|
816
|
+
return cached;
|
|
817
|
+
}
|
|
818
|
+
const tokenHashHex = (0, crypto_1.createHash)('sha1')
|
|
819
|
+
.update(`local_vector_ann:${normalizedToken}`)
|
|
820
|
+
.digest('hex')
|
|
821
|
+
.slice(0, 16);
|
|
822
|
+
const tokenHash = BigInt(`0x${tokenHashHex}`);
|
|
823
|
+
if (LOCAL_VECTOR_TOKEN_HASH_CACHE.size >= LOCAL_VECTOR_ANN_HASH_CACHE_SOFT_LIMIT) {
|
|
824
|
+
const firstKey = LOCAL_VECTOR_TOKEN_HASH_CACHE.keys().next().value;
|
|
825
|
+
if (typeof firstKey === 'string') {
|
|
826
|
+
LOCAL_VECTOR_TOKEN_HASH_CACHE.delete(firstKey);
|
|
827
|
+
}
|
|
828
|
+
}
|
|
829
|
+
LOCAL_VECTOR_TOKEN_HASH_CACHE.set(normalizedToken, tokenHash);
|
|
830
|
+
return tokenHash;
|
|
831
|
+
}
|
|
832
|
+
function computeWeightedSimHash(weights) {
|
|
833
|
+
if (weights.size <= 0) {
|
|
834
|
+
return 0n;
|
|
835
|
+
}
|
|
836
|
+
const accumulator = new Array(64).fill(0);
|
|
837
|
+
weights.forEach((weight, token) => {
|
|
838
|
+
const numericWeight = Number(weight);
|
|
839
|
+
if (!Number.isFinite(numericWeight) || numericWeight <= 0) {
|
|
840
|
+
return;
|
|
841
|
+
}
|
|
842
|
+
const tokenHash = getLocalVectorTokenHash64(token);
|
|
843
|
+
for (let bitIndex = 0; bitIndex < 64; bitIndex += 1) {
|
|
844
|
+
const bitMask = (tokenHash >> BigInt(bitIndex)) & 1n;
|
|
845
|
+
accumulator[bitIndex] += bitMask === 1n ? numericWeight : -numericWeight;
|
|
846
|
+
}
|
|
847
|
+
});
|
|
848
|
+
let signature = 0n;
|
|
849
|
+
for (let bitIndex = 0; bitIndex < 64; bitIndex += 1) {
|
|
850
|
+
if (accumulator[bitIndex] >= 0) {
|
|
851
|
+
signature |= (1n << BigInt(bitIndex));
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
return signature;
|
|
855
|
+
}
|
|
856
|
+
function computeSimHashPrefix(signature, prefixBits) {
|
|
857
|
+
const normalizedBits = Math.max(1, Math.min(64, Math.floor(Number(prefixBits) || 0)));
|
|
858
|
+
const shiftBits = Math.max(0, 64 - normalizedBits);
|
|
859
|
+
const prefixValue = shiftBits > 0
|
|
860
|
+
? (signature >> BigInt(shiftBits))
|
|
861
|
+
: signature;
|
|
862
|
+
const width = Math.max(1, Math.ceil(normalizedBits / 4));
|
|
863
|
+
return prefixValue.toString(16).padStart(width, '0');
|
|
864
|
+
}
|
|
865
|
+
function buildLocalVectorAnnStructures(entriesByAtomId) {
|
|
866
|
+
const tokenToAtomIds = new Map();
|
|
867
|
+
const signatureBuckets = new Map();
|
|
868
|
+
entriesByAtomId.forEach((entry, atomId) => {
|
|
869
|
+
entry.tokens.forEach((token) => {
|
|
870
|
+
if (!token) {
|
|
871
|
+
return;
|
|
872
|
+
}
|
|
873
|
+
const postingList = tokenToAtomIds.get(token) || [];
|
|
874
|
+
postingList.push(atomId);
|
|
875
|
+
tokenToAtomIds.set(token, postingList);
|
|
876
|
+
});
|
|
877
|
+
const prefix = entry.signaturePrefix;
|
|
878
|
+
if (!prefix) {
|
|
879
|
+
return;
|
|
880
|
+
}
|
|
881
|
+
const bucket = signatureBuckets.get(prefix) || [];
|
|
882
|
+
bucket.push(atomId);
|
|
883
|
+
signatureBuckets.set(prefix, bucket);
|
|
884
|
+
});
|
|
885
|
+
return {
|
|
886
|
+
tokenToAtomIds,
|
|
887
|
+
signatureBuckets,
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
function selectLocalVectorAnnCandidatesByDefaultStrategy(input) {
|
|
891
|
+
if (!input.annPrefilterEnabled) {
|
|
892
|
+
return {
|
|
893
|
+
used: false,
|
|
894
|
+
candidateAtomIds: [],
|
|
895
|
+
mode: 'full_scan',
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
if (input.atomCount < LOCAL_VECTOR_ANN_MIN_ATOMS) {
|
|
899
|
+
return {
|
|
900
|
+
used: false,
|
|
901
|
+
candidateAtomIds: [],
|
|
902
|
+
mode: 'full_scan',
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
const prioritizedTokens = uniqueTokens([
|
|
906
|
+
...Array.from(input.queryWeights.entries())
|
|
907
|
+
.filter((entry) => entry[1] > 0)
|
|
908
|
+
.sort((left, right) => right[1] - left[1])
|
|
909
|
+
.map((entry) => entry[0]),
|
|
910
|
+
...input.queryTokens,
|
|
911
|
+
]).slice(0, LOCAL_VECTOR_ANN_TOP_QUERY_TOKENS);
|
|
912
|
+
if (prioritizedTokens.length <= 0) {
|
|
913
|
+
return {
|
|
914
|
+
used: false,
|
|
915
|
+
candidateAtomIds: [],
|
|
916
|
+
mode: 'full_scan',
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
const targetCandidateCount = Math.min(input.atomCount, Math.max(LOCAL_VECTOR_ANN_CANDIDATE_MIN_FLOOR, Math.max(1, input.topK) * LOCAL_VECTOR_ANN_CANDIDATE_MULTIPLIER));
|
|
920
|
+
const minimumCandidateCount = Math.min(input.atomCount, Math.max(Math.max(1, input.topK) * 2, Math.floor(LOCAL_VECTOR_ANN_CANDIDATE_MIN_FLOOR / 2)));
|
|
921
|
+
const candidateAtomIds = new Set();
|
|
922
|
+
let tokenPrefilterUsed = false;
|
|
923
|
+
prioritizedTokens.forEach((token) => {
|
|
924
|
+
if (candidateAtomIds.size >= targetCandidateCount) {
|
|
925
|
+
return;
|
|
926
|
+
}
|
|
927
|
+
const postingList = input.tokenToAtomIds.get(token);
|
|
928
|
+
if (!postingList || postingList.length <= 0) {
|
|
929
|
+
return;
|
|
930
|
+
}
|
|
931
|
+
tokenPrefilterUsed = true;
|
|
932
|
+
postingList.forEach((atomId) => {
|
|
933
|
+
if (candidateAtomIds.size >= targetCandidateCount) {
|
|
934
|
+
return;
|
|
935
|
+
}
|
|
936
|
+
const normalizedAtomId = String(atomId || '').trim();
|
|
937
|
+
if (normalizedAtomId) {
|
|
938
|
+
candidateAtomIds.add(normalizedAtomId);
|
|
939
|
+
}
|
|
940
|
+
});
|
|
941
|
+
});
|
|
942
|
+
let signaturePrefilterUsed = false;
|
|
943
|
+
if (candidateAtomIds.size < targetCandidateCount && input.queryWeights.size > 0) {
|
|
944
|
+
const querySignature = computeWeightedSimHash(new Map(input.queryWeights));
|
|
945
|
+
const queryPrefix = computeSimHashPrefix(querySignature, LOCAL_VECTOR_ANN_SIGNATURE_PREFIX_BITS);
|
|
946
|
+
const signatureBucket = input.signatureBuckets.get(queryPrefix);
|
|
947
|
+
if (signatureBucket && signatureBucket.length > 0) {
|
|
948
|
+
signaturePrefilterUsed = true;
|
|
949
|
+
signatureBucket.forEach((atomId) => {
|
|
950
|
+
if (candidateAtomIds.size >= targetCandidateCount) {
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
const normalizedAtomId = String(atomId || '').trim();
|
|
954
|
+
if (normalizedAtomId) {
|
|
955
|
+
candidateAtomIds.add(normalizedAtomId);
|
|
956
|
+
}
|
|
957
|
+
});
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
if (!tokenPrefilterUsed || candidateAtomIds.size < minimumCandidateCount) {
|
|
961
|
+
return {
|
|
962
|
+
used: false,
|
|
963
|
+
candidateAtomIds: [],
|
|
964
|
+
mode: 'full_scan',
|
|
965
|
+
};
|
|
966
|
+
}
|
|
967
|
+
return {
|
|
968
|
+
used: true,
|
|
969
|
+
candidateAtomIds: Array.from(candidateAtomIds),
|
|
970
|
+
mode: signaturePrefilterUsed ? 'token_signature_prefilter' : 'token_prefilter',
|
|
971
|
+
};
|
|
972
|
+
}
|
|
973
|
+
const DEFAULT_LOCAL_VECTOR_ACCELERATION_ADAPTER = {
|
|
974
|
+
id: LOCAL_VECTOR_ACCELERATION_ADAPTER_ID,
|
|
975
|
+
syncIndex: () => ({
|
|
976
|
+
synced: true,
|
|
977
|
+
}),
|
|
978
|
+
selectCandidates: selectLocalVectorAnnCandidatesByDefaultStrategy,
|
|
979
|
+
getHealth: () => ({
|
|
980
|
+
status: 'ready',
|
|
981
|
+
message: 'local_ann_prefilter_active',
|
|
982
|
+
checkedAt: new Date().toISOString(),
|
|
983
|
+
indexSyncStatus: 'ready',
|
|
984
|
+
indexSyncMessage: 'local_adapter_index_sync_not_required',
|
|
985
|
+
representationVersion: LOCAL_VECTOR_REPRESENTATION_VERSION,
|
|
986
|
+
embeddingModelId: LOCAL_VECTOR_EMBEDDING_MODEL_ID,
|
|
987
|
+
representationStatus: 'aligned',
|
|
988
|
+
representationStatusReason: 'local_adapter_representation_aligned',
|
|
989
|
+
}),
|
|
990
|
+
};
|
|
991
|
+
async function selectLocalVectorAnnCandidates(params) {
|
|
992
|
+
const adapterId = String(params.accelerationAdapter?.id || '').trim() || LOCAL_VECTOR_ACCELERATION_ADAPTER_ID;
|
|
993
|
+
try {
|
|
994
|
+
params.signal?.throwIfAborted();
|
|
995
|
+
if (typeof params.accelerationAdapter.syncIndex === 'function') {
|
|
996
|
+
await params.accelerationAdapter.syncIndex({
|
|
997
|
+
signal: params.signal,
|
|
998
|
+
atomCount: params.index.atomCount,
|
|
999
|
+
tokenToAtomIds: params.index.tokenToAtomIds,
|
|
1000
|
+
signatureBuckets: params.index.signatureBuckets,
|
|
1001
|
+
representationVersion: LOCAL_VECTOR_REPRESENTATION_VERSION,
|
|
1002
|
+
embeddingModelId: LOCAL_VECTOR_EMBEDDING_MODEL_ID,
|
|
1003
|
+
embeddingDimension: params.index.documentFrequency.size,
|
|
1004
|
+
indexSignature: params.index.signature,
|
|
1005
|
+
});
|
|
1006
|
+
}
|
|
1007
|
+
params.signal?.throwIfAborted();
|
|
1008
|
+
const rawSelection = await params.accelerationAdapter.selectCandidates({
|
|
1009
|
+
signal: params.signal,
|
|
1010
|
+
atomCount: params.index.atomCount,
|
|
1011
|
+
queryTokens: [...params.queryTokens],
|
|
1012
|
+
queryWeights: params.queryWeights,
|
|
1013
|
+
topK: params.topK,
|
|
1014
|
+
tokenToAtomIds: params.index.tokenToAtomIds,
|
|
1015
|
+
signatureBuckets: params.index.signatureBuckets,
|
|
1016
|
+
annPrefilterEnabled: params.annPrefilterEnabled,
|
|
1017
|
+
representationVersion: LOCAL_VECTOR_REPRESENTATION_VERSION,
|
|
1018
|
+
embeddingModelId: LOCAL_VECTOR_EMBEDDING_MODEL_ID,
|
|
1019
|
+
embeddingDimension: params.index.documentFrequency.size,
|
|
1020
|
+
indexSignature: params.index.signature,
|
|
1021
|
+
});
|
|
1022
|
+
params.signal?.throwIfAborted();
|
|
1023
|
+
const mode = (rawSelection?.mode === 'token_prefilter'
|
|
1024
|
+
|| rawSelection?.mode === 'token_signature_prefilter'
|
|
1025
|
+
|| rawSelection?.mode === 'full_scan') ? rawSelection.mode : 'full_scan';
|
|
1026
|
+
const candidateAtomIds = new Set(Array.isArray(rawSelection?.candidateAtomIds)
|
|
1027
|
+
? rawSelection.candidateAtomIds
|
|
1028
|
+
.map((atomId) => String(atomId || '').trim())
|
|
1029
|
+
.filter((atomId) => atomId.length > 0)
|
|
1030
|
+
: []);
|
|
1031
|
+
const used = rawSelection?.used === true
|
|
1032
|
+
&& mode !== 'full_scan'
|
|
1033
|
+
&& candidateAtomIds.size > 0;
|
|
1034
|
+
return {
|
|
1035
|
+
used,
|
|
1036
|
+
candidateAtomIds: used ? candidateAtomIds : new Set(),
|
|
1037
|
+
mode: used ? mode : 'full_scan',
|
|
1038
|
+
adapterId,
|
|
1039
|
+
};
|
|
1040
|
+
}
|
|
1041
|
+
catch (error) {
|
|
1042
|
+
params.signal?.throwIfAborted();
|
|
1043
|
+
const normalizedError = String(error?.message || error || 'unknown_error')
|
|
1044
|
+
.replace(/\s+/g, ' ')
|
|
1045
|
+
.trim()
|
|
1046
|
+
.slice(0, 240);
|
|
1047
|
+
if (params.failureMode === 'fail_closed') {
|
|
1048
|
+
throw new Error(`vector_acceleration_adapter_failure:${adapterId}:${normalizedError || 'unknown_error'}`);
|
|
1049
|
+
}
|
|
1050
|
+
return {
|
|
1051
|
+
used: false,
|
|
1052
|
+
candidateAtomIds: new Set(),
|
|
1053
|
+
mode: 'full_scan',
|
|
1054
|
+
adapterId,
|
|
1055
|
+
adapterError: normalizedError,
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
}
|
|
1059
|
+
class LocalHybridGraphQueryBackend {
|
|
1060
|
+
constructor() {
|
|
1061
|
+
this.id = 'local-hybrid-v1';
|
|
1062
|
+
}
|
|
1063
|
+
async query(context) {
|
|
1064
|
+
const queryVariants = buildQueryTextVariants(context);
|
|
1065
|
+
const querySemanticTokens = buildQuerySemanticTokens(context);
|
|
1066
|
+
const graphFeatureIndex = buildGraphFeatureIndex(context, querySemanticTokens);
|
|
1067
|
+
const candidates = [];
|
|
1068
|
+
for (const [candidateIndex, atom] of context.atoms.entries()) {
|
|
1069
|
+
if (context.signal && candidateIndex % 128 === 0) {
|
|
1070
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
1071
|
+
context.signal.throwIfAborted();
|
|
1072
|
+
}
|
|
1073
|
+
const titleLower = atom.title.toLowerCase();
|
|
1074
|
+
const contentLower = atom.content.toLowerCase();
|
|
1075
|
+
const keywordMatches = context.queryTokens.filter((token) => atom.keywords.includes(token)).length;
|
|
1076
|
+
const titleMatchBonus = queryVariants.some((variant) => titleLower.includes(variant)) ? 2 : 0;
|
|
1077
|
+
const contentMatchBonus = context.queryTokens.filter((token) => contentLower.includes(token)).length * 0.25;
|
|
1078
|
+
const atomSemanticTokens = buildAtomSemanticTokens(atom);
|
|
1079
|
+
const semanticSimilarity = computeJaccard(querySemanticTokens, atomSemanticTokens);
|
|
1080
|
+
const semanticBonus = semanticSimilarity * 1.6;
|
|
1081
|
+
const graphFeatureBonus = computeGraphFeatureScore(context, atom.id, graphFeatureIndex);
|
|
1082
|
+
const score = keywordMatches + titleMatchBonus + contentMatchBonus + semanticBonus + graphFeatureBonus;
|
|
1083
|
+
if (score > 0) {
|
|
1084
|
+
candidates.push({
|
|
1085
|
+
atomId: atom.id,
|
|
1086
|
+
score: Number(clamp(score, 0, 100).toFixed(4)),
|
|
1087
|
+
});
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
candidates.sort((left, right) => right.score - left.score);
|
|
1091
|
+
const maxCandidates = Math.max(context.topK, Math.min(context.atoms.length, context.topK * 4));
|
|
1092
|
+
return {
|
|
1093
|
+
candidates: candidates.slice(0, maxCandidates),
|
|
1094
|
+
trace: {
|
|
1095
|
+
retrievalModes: ['keyword', 'semantic_similarity', 'graph_anchor_distance', 'graph_path_confidence', 'graph_intent_match', 'temporal_filter'],
|
|
1096
|
+
modeWeights: {
|
|
1097
|
+
keyword: 0.32,
|
|
1098
|
+
semantic: 0.2,
|
|
1099
|
+
graph: 0.3,
|
|
1100
|
+
temporal: 0.18,
|
|
1101
|
+
},
|
|
1102
|
+
},
|
|
1103
|
+
};
|
|
1104
|
+
}
|
|
1105
|
+
getDiagnostics() {
|
|
1106
|
+
return {
|
|
1107
|
+
backendId: this.id,
|
|
1108
|
+
ready: true,
|
|
1109
|
+
};
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
exports.LocalHybridGraphQueryBackend = LocalHybridGraphQueryBackend;
|
|
1113
|
+
class KeywordOnlyGraphQueryBackend {
|
|
1114
|
+
constructor() {
|
|
1115
|
+
this.id = 'keyword-only-v1';
|
|
1116
|
+
}
|
|
1117
|
+
async query(context) {
|
|
1118
|
+
const queryVariants = buildQueryTextVariants(context);
|
|
1119
|
+
const candidates = [];
|
|
1120
|
+
for (const [candidateIndex, atom] of context.atoms.entries()) {
|
|
1121
|
+
if (context.signal && candidateIndex % 128 === 0) {
|
|
1122
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
1123
|
+
context.signal.throwIfAborted();
|
|
1124
|
+
}
|
|
1125
|
+
const titleLower = atom.title.toLowerCase();
|
|
1126
|
+
const contentLower = atom.content.toLowerCase();
|
|
1127
|
+
const keywordMatches = context.queryTokens.filter((token) => atom.keywords.includes(token)).length;
|
|
1128
|
+
const titleMatchBonus = queryVariants.some((variant) => titleLower.includes(variant)) ? 2 : 0;
|
|
1129
|
+
const contentMatchBonus = context.queryTokens.filter((token) => contentLower.includes(token)).length * 0.22;
|
|
1130
|
+
const score = keywordMatches + titleMatchBonus + contentMatchBonus;
|
|
1131
|
+
if (score > 0) {
|
|
1132
|
+
candidates.push({
|
|
1133
|
+
atomId: atom.id,
|
|
1134
|
+
score: Number(clamp(score, 0, 100).toFixed(4)),
|
|
1135
|
+
});
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
candidates.sort((left, right) => right.score - left.score);
|
|
1139
|
+
const maxCandidates = Math.max(context.topK, Math.min(context.atoms.length, context.topK * 4));
|
|
1140
|
+
return {
|
|
1141
|
+
candidates: candidates.slice(0, maxCandidates),
|
|
1142
|
+
trace: {
|
|
1143
|
+
retrievalModes: ['keyword', 'temporal_filter'],
|
|
1144
|
+
modeWeights: {
|
|
1145
|
+
keyword: 0.72,
|
|
1146
|
+
graph: 0.1,
|
|
1147
|
+
temporal: 0.18,
|
|
1148
|
+
},
|
|
1149
|
+
},
|
|
1150
|
+
};
|
|
1151
|
+
}
|
|
1152
|
+
getDiagnostics() {
|
|
1153
|
+
return {
|
|
1154
|
+
backendId: this.id,
|
|
1155
|
+
ready: true,
|
|
1156
|
+
};
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
exports.KeywordOnlyGraphQueryBackend = KeywordOnlyGraphQueryBackend;
|
|
1160
|
+
class LocalVectorGraphQueryBackend {
|
|
1161
|
+
constructor(options = {}) {
|
|
1162
|
+
this.id = LOCAL_VECTOR_INDEX_BACKEND_ID;
|
|
1163
|
+
this.activeIndex = null;
|
|
1164
|
+
this.pendingIndexSignature = null;
|
|
1165
|
+
this.pendingIndexBuild = null;
|
|
1166
|
+
this.invalidated = false;
|
|
1167
|
+
this.lastAnnSelectionMode = 'full_scan';
|
|
1168
|
+
this.lastAnnCandidateCount = 0;
|
|
1169
|
+
this.lastAnnAdapterId = LOCAL_VECTOR_ACCELERATION_ADAPTER_ID;
|
|
1170
|
+
this.lastAnnAdapterHealthStatus = 'unknown';
|
|
1171
|
+
this.lastAnnIndexSyncStatus = 'unknown';
|
|
1172
|
+
this.lastAnnIndexSyncRequestCount = 0;
|
|
1173
|
+
this.lastAnnIndexSyncSuccessCount = 0;
|
|
1174
|
+
this.lastAnnIndexSyncFailureCount = 0;
|
|
1175
|
+
this.lastAnnAdapterCircuitState = 'unknown';
|
|
1176
|
+
this.lastAnnAdapterConsecutiveFailures = 0;
|
|
1177
|
+
this.lastAnnAdapterRequestCount = 0;
|
|
1178
|
+
this.lastAnnAdapterRetryCount = 0;
|
|
1179
|
+
this.lastAnnAdapterShortCircuitCount = 0;
|
|
1180
|
+
this.lastAnnAdapterSuccessCount = 0;
|
|
1181
|
+
this.lastAnnAdapterFailureCount = 0;
|
|
1182
|
+
this.lastAnnAdapterHalfOpenProbeSuccessCount = 0;
|
|
1183
|
+
this.lastAnnAdapterHalfOpenProbeFailureCount = 0;
|
|
1184
|
+
this.lastAnnAdapterLastRetryAfterMs = 0;
|
|
1185
|
+
this.lastAnnRepresentationStatus = 'unknown';
|
|
1186
|
+
this.localVectorIndexPath = normalizeVectorIndexPath(options.localVectorIndexPath);
|
|
1187
|
+
this.localVectorAnnPrefilterEnabled = options.localVectorAnnPrefilterEnabled !== false;
|
|
1188
|
+
const providedAdapter = options.localVectorAccelerationAdapter;
|
|
1189
|
+
const normalizedAdapterId = String(providedAdapter?.id || '').trim();
|
|
1190
|
+
this.localVectorAccelerationAdapter = (providedAdapter
|
|
1191
|
+
&& normalizedAdapterId
|
|
1192
|
+
&& typeof providedAdapter.selectCandidates === 'function')
|
|
1193
|
+
? providedAdapter
|
|
1194
|
+
: DEFAULT_LOCAL_VECTOR_ACCELERATION_ADAPTER;
|
|
1195
|
+
this.localVectorAccelerationFailureMode = normalizeLocalVectorAccelerationFailureMode(options.localVectorAccelerationFailureMode);
|
|
1196
|
+
this.localVectorAccelerationRepresentationStrict =
|
|
1197
|
+
options.localVectorAccelerationRepresentationStrict === true;
|
|
1198
|
+
this.refreshAccelerationAdapterHealth();
|
|
1199
|
+
}
|
|
1200
|
+
async query(context) {
|
|
1201
|
+
const indexAtoms = this.resolveIndexAtoms(context);
|
|
1202
|
+
const index = await this.ensureIndex(indexAtoms);
|
|
1203
|
+
const querySemanticTokens = buildQuerySemanticTokens(context);
|
|
1204
|
+
const queryFrequency = buildTokenFrequency(querySemanticTokens);
|
|
1205
|
+
const graphFeatureIndex = buildGraphFeatureIndex(context, querySemanticTokens);
|
|
1206
|
+
const totalDocs = Math.max(1, index.atomCount);
|
|
1207
|
+
const queryWeights = buildTfIdfWeights(queryFrequency, index.documentFrequency, totalDocs);
|
|
1208
|
+
const querySignaturePrefix = computeSimHashPrefix(computeWeightedSimHash(queryWeights), LOCAL_VECTOR_ANN_SIGNATURE_PREFIX_BITS);
|
|
1209
|
+
let annCandidateSelection;
|
|
1210
|
+
try {
|
|
1211
|
+
annCandidateSelection = await selectLocalVectorAnnCandidates({
|
|
1212
|
+
signal: context.signal,
|
|
1213
|
+
index,
|
|
1214
|
+
queryTokens: querySemanticTokens,
|
|
1215
|
+
queryWeights,
|
|
1216
|
+
topK: context.topK,
|
|
1217
|
+
annPrefilterEnabled: this.localVectorAnnPrefilterEnabled,
|
|
1218
|
+
accelerationAdapter: this.localVectorAccelerationAdapter,
|
|
1219
|
+
failureMode: this.localVectorAccelerationFailureMode,
|
|
1220
|
+
});
|
|
1221
|
+
}
|
|
1222
|
+
catch (error) {
|
|
1223
|
+
this.refreshAccelerationAdapterHealth();
|
|
1224
|
+
this.lastAnnSelectionMode = 'full_scan';
|
|
1225
|
+
this.lastAnnCandidateCount = index.atomCount;
|
|
1226
|
+
this.lastAnnAdapterId = String(this.localVectorAccelerationAdapter?.id || '').trim()
|
|
1227
|
+
|| LOCAL_VECTOR_ACCELERATION_ADAPTER_ID;
|
|
1228
|
+
this.lastAnnAdapterError = String(error?.message || error || 'unknown_error')
|
|
1229
|
+
.replace(/\s+/g, ' ')
|
|
1230
|
+
.trim()
|
|
1231
|
+
.slice(0, 240);
|
|
1232
|
+
this.lastError = this.lastAnnAdapterError;
|
|
1233
|
+
throw error;
|
|
1234
|
+
}
|
|
1235
|
+
this.refreshAccelerationAdapterHealth();
|
|
1236
|
+
this.lastAnnSelectionMode = annCandidateSelection.mode;
|
|
1237
|
+
this.lastAnnAdapterId = annCandidateSelection.adapterId;
|
|
1238
|
+
this.lastAnnAdapterError = annCandidateSelection.adapterError;
|
|
1239
|
+
const representationTelemetry = this.resolveAccelerationRepresentationTelemetry(index);
|
|
1240
|
+
if (this.localVectorAccelerationRepresentationStrict
|
|
1241
|
+
&& representationTelemetry.representationStatus === 'mismatch') {
|
|
1242
|
+
const mismatchReason = String(representationTelemetry.representationStatusReason || 'representation_mismatch').trim().replace(/\s+/g, '_').slice(0, 200) || 'representation_mismatch';
|
|
1243
|
+
const strictMismatchError = (`vector_acceleration_representation_mismatch:${this.lastAnnAdapterId || 'unknown'}:${mismatchReason}`);
|
|
1244
|
+
this.lastAnnAdapterError = strictMismatchError;
|
|
1245
|
+
this.lastError = strictMismatchError;
|
|
1246
|
+
throw new Error(strictMismatchError);
|
|
1247
|
+
}
|
|
1248
|
+
const scopedAtomIds = new Set(context.atoms.map((atom) => atom.id));
|
|
1249
|
+
const scopedAnnCandidateAtomIds = annCandidateSelection.used
|
|
1250
|
+
? Array.from(annCandidateSelection.candidateAtomIds.values())
|
|
1251
|
+
.filter((atomId) => scopedAtomIds.has(atomId))
|
|
1252
|
+
: [];
|
|
1253
|
+
const annScopedPrefilterUsable = (annCandidateSelection.used
|
|
1254
|
+
&& scopedAtomIds.size > 0
|
|
1255
|
+
&& scopedAnnCandidateAtomIds.length > 0);
|
|
1256
|
+
const atomIdsToScore = annScopedPrefilterUsable
|
|
1257
|
+
? scopedAnnCandidateAtomIds
|
|
1258
|
+
: context.atoms.map((atom) => atom.id);
|
|
1259
|
+
this.lastAnnCandidateCount = annScopedPrefilterUsable
|
|
1260
|
+
? scopedAnnCandidateAtomIds.length
|
|
1261
|
+
: scopedAtomIds.size;
|
|
1262
|
+
const accelerationMode = (this.localVectorAnnPrefilterEnabled
|
|
1263
|
+
&& annScopedPrefilterUsable
|
|
1264
|
+
&& annCandidateSelection.mode !== 'full_scan') ? 'ann_prefilter' : 'full_scan';
|
|
1265
|
+
const vectorAccelerationTrace = {
|
|
1266
|
+
mode: accelerationMode,
|
|
1267
|
+
selectionMode: annCandidateSelection.mode,
|
|
1268
|
+
failureMode: this.localVectorAccelerationFailureMode,
|
|
1269
|
+
candidateCount: this.lastAnnCandidateCount,
|
|
1270
|
+
adapterId: this.lastAnnAdapterId,
|
|
1271
|
+
adapterError: this.lastAnnAdapterError,
|
|
1272
|
+
healthStatus: this.lastAnnAdapterHealthStatus,
|
|
1273
|
+
circuitState: this.lastAnnAdapterCircuitState,
|
|
1274
|
+
lastRequestId: this.lastAnnAdapterLastRequestId,
|
|
1275
|
+
lastErrorCode: this.lastAnnAdapterLastErrorCode,
|
|
1276
|
+
lastRetryAfterMs: this.lastAnnAdapterLastRetryAfterMs > 0
|
|
1277
|
+
? this.lastAnnAdapterLastRetryAfterMs
|
|
1278
|
+
: undefined,
|
|
1279
|
+
representationVersion: representationTelemetry.representationVersion,
|
|
1280
|
+
embeddingModelId: representationTelemetry.embeddingModelId,
|
|
1281
|
+
embeddingDimension: representationTelemetry.embeddingDimension,
|
|
1282
|
+
indexSignature: representationTelemetry.indexSignature,
|
|
1283
|
+
representationStatus: representationTelemetry.representationStatus,
|
|
1284
|
+
representationStatusReason: representationTelemetry.representationStatusReason,
|
|
1285
|
+
representationStrictMode: this.localVectorAccelerationRepresentationStrict,
|
|
1286
|
+
};
|
|
1287
|
+
const candidates = [];
|
|
1288
|
+
for (const [candidateIndex, atomId] of atomIdsToScore.entries()) {
|
|
1289
|
+
if (context.signal && candidateIndex % 128 === 0) {
|
|
1290
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
1291
|
+
context.signal.throwIfAborted();
|
|
1292
|
+
}
|
|
1293
|
+
const entry = index.entriesByAtomId.get(atomId);
|
|
1294
|
+
if (!entry) {
|
|
1295
|
+
continue;
|
|
1296
|
+
}
|
|
1297
|
+
const cosineSimilarity = computeCosineSimilarity(queryWeights, entry.weights);
|
|
1298
|
+
const semanticOverlap = computeJaccard(querySemanticTokens, entry.tokens);
|
|
1299
|
+
const graphFeatureBonus = computeGraphFeatureScore(context, atomId, graphFeatureIndex);
|
|
1300
|
+
const signatureBonus = entry.signaturePrefix === querySignaturePrefix
|
|
1301
|
+
? LOCAL_VECTOR_ANN_SIGNATURE_SCORE_BONUS
|
|
1302
|
+
: 0;
|
|
1303
|
+
const score = (cosineSimilarity * 4.2) + (semanticOverlap * 1.1) + graphFeatureBonus + signatureBonus;
|
|
1304
|
+
if (score <= 0) {
|
|
1305
|
+
continue;
|
|
1306
|
+
}
|
|
1307
|
+
candidates.push({
|
|
1308
|
+
atomId,
|
|
1309
|
+
score: Number(clamp(score, 0, 100).toFixed(4)),
|
|
1310
|
+
});
|
|
1311
|
+
}
|
|
1312
|
+
candidates.sort((left, right) => right.score - left.score);
|
|
1313
|
+
const maxCandidates = Math.max(context.topK, Math.min(context.atoms.length, context.topK * 4));
|
|
1314
|
+
return {
|
|
1315
|
+
candidates: candidates.slice(0, maxCandidates),
|
|
1316
|
+
trace: {
|
|
1317
|
+
retrievalModes: [
|
|
1318
|
+
'vector_similarity',
|
|
1319
|
+
'semantic_similarity',
|
|
1320
|
+
'graph_anchor_distance',
|
|
1321
|
+
'graph_path_confidence',
|
|
1322
|
+
'graph_intent_match',
|
|
1323
|
+
'temporal_filter',
|
|
1324
|
+
...(annScopedPrefilterUsable ? ['ann_prefilter'] : []),
|
|
1325
|
+
],
|
|
1326
|
+
modeWeights: {
|
|
1327
|
+
vector: 0.58,
|
|
1328
|
+
semantic: 0.14,
|
|
1329
|
+
graph: 0.1,
|
|
1330
|
+
temporal: 0.18,
|
|
1331
|
+
},
|
|
1332
|
+
vectorAcceleration: vectorAccelerationTrace,
|
|
1333
|
+
},
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
resolveIndexAtoms(context) {
|
|
1337
|
+
const atomsById = new Map();
|
|
1338
|
+
const candidateIndexAtoms = (Array.isArray(context.indexAtoms)
|
|
1339
|
+
&& context.indexAtoms.length >= context.atoms.length)
|
|
1340
|
+
? context.indexAtoms
|
|
1341
|
+
: context.atoms;
|
|
1342
|
+
candidateIndexAtoms.forEach((atom) => {
|
|
1343
|
+
if (atom && atom.id) {
|
|
1344
|
+
atomsById.set(atom.id, atom);
|
|
1345
|
+
}
|
|
1346
|
+
});
|
|
1347
|
+
context.atoms.forEach((atom) => {
|
|
1348
|
+
if (atom && atom.id && !atomsById.has(atom.id)) {
|
|
1349
|
+
atomsById.set(atom.id, atom);
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1352
|
+
return Array.from(atomsById.values());
|
|
1353
|
+
}
|
|
1354
|
+
getDiagnostics() {
|
|
1355
|
+
const index = this.activeIndex;
|
|
1356
|
+
const ready = (Boolean(index) && !this.invalidated) || !this.lastError;
|
|
1357
|
+
const status = (index && !this.invalidated)
|
|
1358
|
+
? 'ready'
|
|
1359
|
+
: (this.lastError ? 'unavailable' : 'stale');
|
|
1360
|
+
const accelerationMode = (this.localVectorAnnPrefilterEnabled
|
|
1361
|
+
&& this.lastAnnSelectionMode !== 'full_scan') ? 'ann_prefilter' : 'full_scan';
|
|
1362
|
+
const representationTelemetry = index
|
|
1363
|
+
? this.resolveAccelerationRepresentationTelemetry(index)
|
|
1364
|
+
: {
|
|
1365
|
+
representationVersion: this.lastAnnRepresentationVersion,
|
|
1366
|
+
embeddingModelId: this.lastAnnEmbeddingModelId,
|
|
1367
|
+
embeddingDimension: this.lastAnnEmbeddingDimension,
|
|
1368
|
+
indexSignature: this.lastAnnIndexSignature,
|
|
1369
|
+
representationStatus: this.lastAnnRepresentationStatus,
|
|
1370
|
+
representationStatusReason: this.lastAnnRepresentationStatusReason,
|
|
1371
|
+
};
|
|
1372
|
+
return {
|
|
1373
|
+
backendId: this.id,
|
|
1374
|
+
ready,
|
|
1375
|
+
lastError: this.lastError,
|
|
1376
|
+
vectorIndex: {
|
|
1377
|
+
enabled: true,
|
|
1378
|
+
status,
|
|
1379
|
+
location: this.localVectorIndexPath,
|
|
1380
|
+
signature: index?.signature,
|
|
1381
|
+
builtAt: index?.builtAt,
|
|
1382
|
+
atomCount: index?.atomCount,
|
|
1383
|
+
loadedFromDisk: index?.loadedFromDisk,
|
|
1384
|
+
persisted: index?.persisted,
|
|
1385
|
+
acceleration: {
|
|
1386
|
+
enabled: this.localVectorAnnPrefilterEnabled,
|
|
1387
|
+
mode: accelerationMode,
|
|
1388
|
+
failureMode: this.localVectorAccelerationFailureMode,
|
|
1389
|
+
indexSyncStatus: this.lastAnnIndexSyncStatus,
|
|
1390
|
+
indexSyncMessage: this.lastAnnIndexSyncMessage,
|
|
1391
|
+
lastSyncAt: this.lastAnnIndexLastSyncAt,
|
|
1392
|
+
syncRequestCount: this.lastAnnIndexSyncRequestCount,
|
|
1393
|
+
syncSuccessCount: this.lastAnnIndexSyncSuccessCount,
|
|
1394
|
+
syncFailureCount: this.lastAnnIndexSyncFailureCount,
|
|
1395
|
+
syncedIndexSignature: this.lastAnnIndexSyncedSignature,
|
|
1396
|
+
syncedAtomCount: this.lastAnnIndexSyncedAtomCount,
|
|
1397
|
+
lastSelectionMode: this.lastAnnSelectionMode,
|
|
1398
|
+
lastCandidateCount: this.lastAnnCandidateCount,
|
|
1399
|
+
adapterId: this.lastAnnAdapterId,
|
|
1400
|
+
adapterError: this.lastAnnAdapterError,
|
|
1401
|
+
healthStatus: this.lastAnnAdapterHealthStatus,
|
|
1402
|
+
healthMessage: this.lastAnnAdapterHealthMessage,
|
|
1403
|
+
healthCheckedAt: this.lastAnnAdapterHealthCheckedAt,
|
|
1404
|
+
circuitState: this.lastAnnAdapterCircuitState,
|
|
1405
|
+
consecutiveFailures: this.lastAnnAdapterConsecutiveFailures,
|
|
1406
|
+
requestCount: this.lastAnnAdapterRequestCount,
|
|
1407
|
+
retryCount: this.lastAnnAdapterRetryCount,
|
|
1408
|
+
shortCircuitCount: this.lastAnnAdapterShortCircuitCount,
|
|
1409
|
+
successCount: this.lastAnnAdapterSuccessCount,
|
|
1410
|
+
failureCount: this.lastAnnAdapterFailureCount,
|
|
1411
|
+
halfOpenProbeSuccessCount: this.lastAnnAdapterHalfOpenProbeSuccessCount,
|
|
1412
|
+
halfOpenProbeFailureCount: this.lastAnnAdapterHalfOpenProbeFailureCount,
|
|
1413
|
+
lastSuccessAt: this.lastAnnAdapterLastSuccessAt,
|
|
1414
|
+
lastFailureAt: this.lastAnnAdapterLastFailureAt,
|
|
1415
|
+
circuitOpenedAt: this.lastAnnAdapterCircuitOpenedAt,
|
|
1416
|
+
lastRequestId: this.lastAnnAdapterLastRequestId,
|
|
1417
|
+
lastErrorCode: this.lastAnnAdapterLastErrorCode,
|
|
1418
|
+
lastRetryAfterMs: this.lastAnnAdapterLastRetryAfterMs > 0
|
|
1419
|
+
? this.lastAnnAdapterLastRetryAfterMs
|
|
1420
|
+
: undefined,
|
|
1421
|
+
representationVersion: representationTelemetry.representationVersion,
|
|
1422
|
+
embeddingModelId: representationTelemetry.embeddingModelId,
|
|
1423
|
+
embeddingDimension: representationTelemetry.embeddingDimension,
|
|
1424
|
+
indexSignature: representationTelemetry.indexSignature,
|
|
1425
|
+
representationStatus: representationTelemetry.representationStatus,
|
|
1426
|
+
representationStatusReason: representationTelemetry.representationStatusReason,
|
|
1427
|
+
representationStrictMode: this.localVectorAccelerationRepresentationStrict,
|
|
1428
|
+
},
|
|
1429
|
+
},
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
invalidate(reason) {
|
|
1433
|
+
this.invalidated = true;
|
|
1434
|
+
this.invalidationReason = String(reason || '').trim().slice(0, 160) || undefined;
|
|
1435
|
+
}
|
|
1436
|
+
refreshAccelerationAdapterHealth() {
|
|
1437
|
+
if (!this.localVectorAccelerationAdapter || typeof this.localVectorAccelerationAdapter.getHealth !== 'function') {
|
|
1438
|
+
this.lastAnnAdapterHealthStatus = 'unknown';
|
|
1439
|
+
this.lastAnnAdapterHealthMessage = 'adapter_health_not_reported';
|
|
1440
|
+
this.lastAnnAdapterHealthCheckedAt = new Date().toISOString();
|
|
1441
|
+
this.lastAnnIndexSyncStatus = 'unknown';
|
|
1442
|
+
this.lastAnnIndexSyncMessage = 'adapter_health_not_reported';
|
|
1443
|
+
this.lastAnnIndexLastSyncAt = undefined;
|
|
1444
|
+
this.lastAnnIndexSyncRequestCount = 0;
|
|
1445
|
+
this.lastAnnIndexSyncSuccessCount = 0;
|
|
1446
|
+
this.lastAnnIndexSyncFailureCount = 0;
|
|
1447
|
+
this.lastAnnIndexSyncedSignature = undefined;
|
|
1448
|
+
this.lastAnnIndexSyncedAtomCount = undefined;
|
|
1449
|
+
this.lastAnnAdapterCircuitState = 'unknown';
|
|
1450
|
+
this.lastAnnAdapterConsecutiveFailures = 0;
|
|
1451
|
+
this.lastAnnAdapterRequestCount = 0;
|
|
1452
|
+
this.lastAnnAdapterRetryCount = 0;
|
|
1453
|
+
this.lastAnnAdapterShortCircuitCount = 0;
|
|
1454
|
+
this.lastAnnAdapterSuccessCount = 0;
|
|
1455
|
+
this.lastAnnAdapterFailureCount = 0;
|
|
1456
|
+
this.lastAnnAdapterHalfOpenProbeSuccessCount = 0;
|
|
1457
|
+
this.lastAnnAdapterHalfOpenProbeFailureCount = 0;
|
|
1458
|
+
this.lastAnnAdapterLastSuccessAt = undefined;
|
|
1459
|
+
this.lastAnnAdapterLastFailureAt = undefined;
|
|
1460
|
+
this.lastAnnAdapterCircuitOpenedAt = undefined;
|
|
1461
|
+
this.lastAnnAdapterLastRequestId = undefined;
|
|
1462
|
+
this.lastAnnAdapterLastErrorCode = undefined;
|
|
1463
|
+
this.lastAnnAdapterLastRetryAfterMs = 0;
|
|
1464
|
+
this.lastAnnRepresentationVersion = undefined;
|
|
1465
|
+
this.lastAnnEmbeddingModelId = undefined;
|
|
1466
|
+
this.lastAnnEmbeddingDimension = undefined;
|
|
1467
|
+
this.lastAnnIndexSignature = undefined;
|
|
1468
|
+
this.lastAnnRepresentationStatus = 'unknown';
|
|
1469
|
+
this.lastAnnRepresentationStatusReason = 'adapter_health_not_reported';
|
|
1470
|
+
return;
|
|
1471
|
+
}
|
|
1472
|
+
try {
|
|
1473
|
+
const health = this.localVectorAccelerationAdapter.getHealth();
|
|
1474
|
+
const normalizedStatus = String(health?.status || '').trim().toLowerCase();
|
|
1475
|
+
this.lastAnnAdapterHealthStatus = (normalizedStatus === 'ready'
|
|
1476
|
+
|| normalizedStatus === 'degraded'
|
|
1477
|
+
|| normalizedStatus === 'unavailable'
|
|
1478
|
+
|| normalizedStatus === 'unknown') ? normalizedStatus : 'unknown';
|
|
1479
|
+
this.lastAnnAdapterHealthMessage = String(health?.message || '').trim().slice(0, 240) || undefined;
|
|
1480
|
+
this.lastAnnAdapterHealthCheckedAt = String(health?.checkedAt || '').trim() || new Date().toISOString();
|
|
1481
|
+
const normalizedIndexSyncStatus = String(health?.indexSyncStatus || '').trim().toLowerCase();
|
|
1482
|
+
this.lastAnnIndexSyncStatus = (normalizedIndexSyncStatus === 'ready'
|
|
1483
|
+
|| normalizedIndexSyncStatus === 'degraded'
|
|
1484
|
+
|| normalizedIndexSyncStatus === 'unavailable'
|
|
1485
|
+
|| normalizedIndexSyncStatus === 'unknown') ? normalizedIndexSyncStatus : 'unknown';
|
|
1486
|
+
this.lastAnnIndexSyncMessage = String(health?.indexSyncMessage || '').trim().slice(0, 240) || undefined;
|
|
1487
|
+
this.lastAnnIndexLastSyncAt = String(health?.lastSyncAt || '').trim() || undefined;
|
|
1488
|
+
this.lastAnnIndexSyncRequestCount = Math.max(0, Math.floor(Number(health?.syncRequestCount || 0)));
|
|
1489
|
+
this.lastAnnIndexSyncSuccessCount = Math.max(0, Math.floor(Number(health?.syncSuccessCount || 0)));
|
|
1490
|
+
this.lastAnnIndexSyncFailureCount = Math.max(0, Math.floor(Number(health?.syncFailureCount || 0)));
|
|
1491
|
+
this.lastAnnIndexSyncedSignature = String(health?.syncedIndexSignature || '').trim().slice(0, 200) || undefined;
|
|
1492
|
+
this.lastAnnIndexSyncedAtomCount = Number.isFinite(Number(health?.syncedAtomCount))
|
|
1493
|
+
? Math.max(0, Math.floor(Number(health?.syncedAtomCount || 0)))
|
|
1494
|
+
: undefined;
|
|
1495
|
+
const normalizedCircuitState = String(health?.circuitState || '').trim().toLowerCase();
|
|
1496
|
+
this.lastAnnAdapterCircuitState = (normalizedCircuitState === 'closed'
|
|
1497
|
+
|| normalizedCircuitState === 'open'
|
|
1498
|
+
|| normalizedCircuitState === 'half_open'
|
|
1499
|
+
|| normalizedCircuitState === 'unknown') ? normalizedCircuitState : 'unknown';
|
|
1500
|
+
this.lastAnnAdapterConsecutiveFailures = Math.max(0, Math.floor(Number(health?.consecutiveFailures || 0)));
|
|
1501
|
+
this.lastAnnAdapterRequestCount = Math.max(0, Math.floor(Number(health?.requestCount || 0)));
|
|
1502
|
+
this.lastAnnAdapterRetryCount = Math.max(0, Math.floor(Number(health?.retryCount || 0)));
|
|
1503
|
+
this.lastAnnAdapterShortCircuitCount = Math.max(0, Math.floor(Number(health?.shortCircuitCount || 0)));
|
|
1504
|
+
this.lastAnnAdapterSuccessCount = Math.max(0, Math.floor(Number(health?.successCount || 0)));
|
|
1505
|
+
this.lastAnnAdapterFailureCount = Math.max(0, Math.floor(Number(health?.failureCount || 0)));
|
|
1506
|
+
this.lastAnnAdapterHalfOpenProbeSuccessCount = Math.max(0, Math.floor(Number(health?.halfOpenProbeSuccessCount || 0)));
|
|
1507
|
+
this.lastAnnAdapterHalfOpenProbeFailureCount = Math.max(0, Math.floor(Number(health?.halfOpenProbeFailureCount || 0)));
|
|
1508
|
+
this.lastAnnAdapterLastSuccessAt = String(health?.lastSuccessAt || '').trim() || undefined;
|
|
1509
|
+
this.lastAnnAdapterLastFailureAt = String(health?.lastFailureAt || '').trim() || undefined;
|
|
1510
|
+
this.lastAnnAdapterCircuitOpenedAt = String(health?.circuitOpenedAt || '').trim() || undefined;
|
|
1511
|
+
this.lastAnnAdapterLastRequestId = String(health?.lastRequestId || '').trim() || undefined;
|
|
1512
|
+
this.lastAnnAdapterLastErrorCode = String(health?.lastErrorCode || '').trim() || undefined;
|
|
1513
|
+
this.lastAnnAdapterLastRetryAfterMs = Math.max(0, Math.floor(Number(health?.lastRetryAfterMs || 0)));
|
|
1514
|
+
this.lastAnnRepresentationVersion = String(health?.representationVersion || '').trim().slice(0, 160) || undefined;
|
|
1515
|
+
this.lastAnnEmbeddingModelId = String(health?.embeddingModelId || '').trim().slice(0, 160) || undefined;
|
|
1516
|
+
this.lastAnnEmbeddingDimension = Number.isFinite(Number(health?.embeddingDimension))
|
|
1517
|
+
? Math.max(0, Math.floor(Number(health?.embeddingDimension || 0)))
|
|
1518
|
+
: undefined;
|
|
1519
|
+
this.lastAnnIndexSignature = String(health?.indexSignature || '')
|
|
1520
|
+
.trim()
|
|
1521
|
+
.replace(/[^a-zA-Z0-9:_-]+/g, '')
|
|
1522
|
+
.slice(0, 200) || undefined;
|
|
1523
|
+
const rawRepresentationStatus = String(health?.representationStatus || '').trim().toLowerCase();
|
|
1524
|
+
this.lastAnnRepresentationStatus = (rawRepresentationStatus === 'aligned'
|
|
1525
|
+
|| rawRepresentationStatus === 'mismatch'
|
|
1526
|
+
|| rawRepresentationStatus === 'unknown') ? rawRepresentationStatus : 'unknown';
|
|
1527
|
+
this.lastAnnRepresentationStatusReason = String(health?.representationStatusReason || '')
|
|
1528
|
+
.trim()
|
|
1529
|
+
.replace(/\s+/g, ' ')
|
|
1530
|
+
.slice(0, 240) || undefined;
|
|
1531
|
+
}
|
|
1532
|
+
catch (error) {
|
|
1533
|
+
this.lastAnnAdapterHealthStatus = 'unavailable';
|
|
1534
|
+
this.lastAnnAdapterHealthMessage = String(error?.message || error).slice(0, 240);
|
|
1535
|
+
this.lastAnnAdapterHealthCheckedAt = new Date().toISOString();
|
|
1536
|
+
this.lastAnnIndexSyncStatus = 'unknown';
|
|
1537
|
+
this.lastAnnIndexSyncMessage = 'adapter_health_probe_failed';
|
|
1538
|
+
this.lastAnnIndexLastSyncAt = undefined;
|
|
1539
|
+
this.lastAnnIndexSyncRequestCount = 0;
|
|
1540
|
+
this.lastAnnIndexSyncSuccessCount = 0;
|
|
1541
|
+
this.lastAnnIndexSyncFailureCount = 0;
|
|
1542
|
+
this.lastAnnIndexSyncedSignature = undefined;
|
|
1543
|
+
this.lastAnnIndexSyncedAtomCount = undefined;
|
|
1544
|
+
this.lastAnnAdapterCircuitState = 'unknown';
|
|
1545
|
+
this.lastAnnAdapterConsecutiveFailures = 0;
|
|
1546
|
+
this.lastAnnAdapterRequestCount = 0;
|
|
1547
|
+
this.lastAnnAdapterRetryCount = 0;
|
|
1548
|
+
this.lastAnnAdapterShortCircuitCount = 0;
|
|
1549
|
+
this.lastAnnAdapterSuccessCount = 0;
|
|
1550
|
+
this.lastAnnAdapterFailureCount = 0;
|
|
1551
|
+
this.lastAnnAdapterHalfOpenProbeSuccessCount = 0;
|
|
1552
|
+
this.lastAnnAdapterHalfOpenProbeFailureCount = 0;
|
|
1553
|
+
this.lastAnnAdapterLastSuccessAt = undefined;
|
|
1554
|
+
this.lastAnnAdapterLastFailureAt = undefined;
|
|
1555
|
+
this.lastAnnAdapterCircuitOpenedAt = undefined;
|
|
1556
|
+
this.lastAnnAdapterLastRequestId = undefined;
|
|
1557
|
+
this.lastAnnAdapterLastErrorCode = undefined;
|
|
1558
|
+
this.lastAnnAdapterLastRetryAfterMs = 0;
|
|
1559
|
+
this.lastAnnRepresentationVersion = undefined;
|
|
1560
|
+
this.lastAnnEmbeddingModelId = undefined;
|
|
1561
|
+
this.lastAnnEmbeddingDimension = undefined;
|
|
1562
|
+
this.lastAnnIndexSignature = undefined;
|
|
1563
|
+
this.lastAnnRepresentationStatus = 'unknown';
|
|
1564
|
+
this.lastAnnRepresentationStatusReason = 'adapter_health_probe_failed';
|
|
1565
|
+
}
|
|
1566
|
+
}
|
|
1567
|
+
resolveAccelerationRepresentationTelemetry(index) {
|
|
1568
|
+
const expectedRepresentationVersion = LOCAL_VECTOR_REPRESENTATION_VERSION;
|
|
1569
|
+
const expectedEmbeddingModelId = LOCAL_VECTOR_EMBEDDING_MODEL_ID;
|
|
1570
|
+
const expectedEmbeddingDimension = Math.max(0, Math.floor(Number(index.documentFrequency.size || 0)));
|
|
1571
|
+
const expectedIndexSignature = String(index.signature || '').trim().slice(0, 200);
|
|
1572
|
+
const adapterId = String(this.lastAnnAdapterId || '').trim().toLowerCase();
|
|
1573
|
+
const localAdapterPath = (!adapterId
|
|
1574
|
+
|| adapterId === LOCAL_VECTOR_ACCELERATION_ADAPTER_ID
|
|
1575
|
+
|| adapterId.includes('local-vector-acceleration'));
|
|
1576
|
+
let representationVersion = this.lastAnnRepresentationVersion;
|
|
1577
|
+
let embeddingModelId = this.lastAnnEmbeddingModelId;
|
|
1578
|
+
let embeddingDimension = this.lastAnnEmbeddingDimension;
|
|
1579
|
+
let indexSignature = this.lastAnnIndexSignature;
|
|
1580
|
+
let representationStatus = this.lastAnnRepresentationStatus;
|
|
1581
|
+
let representationStatusReason = this.lastAnnRepresentationStatusReason;
|
|
1582
|
+
const mismatchReasons = [];
|
|
1583
|
+
let comparableFields = 0;
|
|
1584
|
+
if (representationVersion) {
|
|
1585
|
+
comparableFields += 1;
|
|
1586
|
+
if (representationVersion !== expectedRepresentationVersion) {
|
|
1587
|
+
mismatchReasons.push('representation_version');
|
|
1588
|
+
}
|
|
1589
|
+
}
|
|
1590
|
+
if (embeddingModelId) {
|
|
1591
|
+
comparableFields += 1;
|
|
1592
|
+
if (embeddingModelId !== expectedEmbeddingModelId) {
|
|
1593
|
+
mismatchReasons.push('embedding_model_id');
|
|
1594
|
+
}
|
|
1595
|
+
}
|
|
1596
|
+
if (typeof embeddingDimension === 'number' && embeddingDimension > 0) {
|
|
1597
|
+
comparableFields += 1;
|
|
1598
|
+
if (embeddingDimension !== expectedEmbeddingDimension) {
|
|
1599
|
+
mismatchReasons.push('embedding_dimension');
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
if (indexSignature) {
|
|
1603
|
+
comparableFields += 1;
|
|
1604
|
+
if (indexSignature !== expectedIndexSignature) {
|
|
1605
|
+
mismatchReasons.push('index_signature');
|
|
1606
|
+
}
|
|
1607
|
+
}
|
|
1608
|
+
if (localAdapterPath) {
|
|
1609
|
+
representationVersion = expectedRepresentationVersion;
|
|
1610
|
+
embeddingModelId = expectedEmbeddingModelId;
|
|
1611
|
+
embeddingDimension = expectedEmbeddingDimension;
|
|
1612
|
+
indexSignature = expectedIndexSignature;
|
|
1613
|
+
representationStatus = 'aligned';
|
|
1614
|
+
representationStatusReason = 'local_adapter_representation_aligned';
|
|
1615
|
+
}
|
|
1616
|
+
else if (representationStatus === 'unknown') {
|
|
1617
|
+
if (mismatchReasons.length > 0) {
|
|
1618
|
+
representationStatus = 'mismatch';
|
|
1619
|
+
representationStatusReason = `mismatch:${mismatchReasons.join(',')}`;
|
|
1620
|
+
}
|
|
1621
|
+
else if (comparableFields > 0) {
|
|
1622
|
+
representationStatus = 'aligned';
|
|
1623
|
+
representationStatusReason = representationStatusReason || 'adapter_representation_metadata_aligned';
|
|
1624
|
+
}
|
|
1625
|
+
else {
|
|
1626
|
+
representationStatus = 'unknown';
|
|
1627
|
+
representationStatusReason = representationStatusReason || 'adapter_representation_metadata_missing';
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
else if (representationStatus === 'mismatch' && !representationStatusReason) {
|
|
1631
|
+
representationStatusReason = mismatchReasons.length > 0
|
|
1632
|
+
? `mismatch:${mismatchReasons.join(',')}`
|
|
1633
|
+
: 'adapter_reported_mismatch';
|
|
1634
|
+
}
|
|
1635
|
+
else if (representationStatus === 'aligned' && !representationStatusReason) {
|
|
1636
|
+
representationStatusReason = 'adapter_representation_metadata_aligned';
|
|
1637
|
+
}
|
|
1638
|
+
this.lastAnnRepresentationVersion = representationVersion || undefined;
|
|
1639
|
+
this.lastAnnEmbeddingModelId = embeddingModelId || undefined;
|
|
1640
|
+
this.lastAnnEmbeddingDimension = (typeof embeddingDimension === 'number'
|
|
1641
|
+
&& Number.isFinite(embeddingDimension)
|
|
1642
|
+
&& embeddingDimension > 0)
|
|
1643
|
+
? Math.floor(embeddingDimension)
|
|
1644
|
+
: undefined;
|
|
1645
|
+
this.lastAnnIndexSignature = indexSignature || undefined;
|
|
1646
|
+
this.lastAnnRepresentationStatus = representationStatus;
|
|
1647
|
+
this.lastAnnRepresentationStatusReason = representationStatusReason || undefined;
|
|
1648
|
+
return {
|
|
1649
|
+
representationVersion: this.lastAnnRepresentationVersion,
|
|
1650
|
+
embeddingModelId: this.lastAnnEmbeddingModelId,
|
|
1651
|
+
embeddingDimension: this.lastAnnEmbeddingDimension,
|
|
1652
|
+
indexSignature: this.lastAnnIndexSignature,
|
|
1653
|
+
representationStatus: this.lastAnnRepresentationStatus,
|
|
1654
|
+
representationStatusReason: this.lastAnnRepresentationStatusReason,
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
async ensureIndex(atoms) {
|
|
1658
|
+
const signature = computeLocalVectorSignature(atoms);
|
|
1659
|
+
if (!this.invalidated && this.activeIndex && this.activeIndex.signature === signature) {
|
|
1660
|
+
return this.activeIndex;
|
|
1661
|
+
}
|
|
1662
|
+
if (this.pendingIndexBuild && this.pendingIndexSignature === signature) {
|
|
1663
|
+
return this.pendingIndexBuild;
|
|
1664
|
+
}
|
|
1665
|
+
this.pendingIndexSignature = signature;
|
|
1666
|
+
this.pendingIndexBuild = this.loadOrBuildIndex(signature, atoms)
|
|
1667
|
+
.finally(() => {
|
|
1668
|
+
this.pendingIndexBuild = null;
|
|
1669
|
+
this.pendingIndexSignature = null;
|
|
1670
|
+
});
|
|
1671
|
+
return this.pendingIndexBuild;
|
|
1672
|
+
}
|
|
1673
|
+
async loadOrBuildIndex(signature, atoms) {
|
|
1674
|
+
const fromDisk = await this.tryLoadIndexFromDisk(signature);
|
|
1675
|
+
if (fromDisk) {
|
|
1676
|
+
this.activeIndex = fromDisk;
|
|
1677
|
+
this.invalidated = false;
|
|
1678
|
+
this.invalidationReason = undefined;
|
|
1679
|
+
this.lastError = undefined;
|
|
1680
|
+
return fromDisk;
|
|
1681
|
+
}
|
|
1682
|
+
const builtAt = new Date().toISOString();
|
|
1683
|
+
const memoryIndex = this.buildIndexFromAtoms({
|
|
1684
|
+
signature,
|
|
1685
|
+
builtAt,
|
|
1686
|
+
atoms,
|
|
1687
|
+
loadedFromDisk: false,
|
|
1688
|
+
persisted: false,
|
|
1689
|
+
});
|
|
1690
|
+
if (this.localVectorIndexPath) {
|
|
1691
|
+
const persisted = await this.tryPersistIndexToDisk(memoryIndex);
|
|
1692
|
+
memoryIndex.persisted = persisted;
|
|
1693
|
+
}
|
|
1694
|
+
this.activeIndex = memoryIndex;
|
|
1695
|
+
this.invalidated = false;
|
|
1696
|
+
this.invalidationReason = undefined;
|
|
1697
|
+
if (memoryIndex.persisted || !this.localVectorIndexPath) {
|
|
1698
|
+
this.lastError = undefined;
|
|
1699
|
+
}
|
|
1700
|
+
return memoryIndex;
|
|
1701
|
+
}
|
|
1702
|
+
buildIndexFromAtoms(params) {
|
|
1703
|
+
const atomTokensById = new Map();
|
|
1704
|
+
const documentFrequency = new Map();
|
|
1705
|
+
params.atoms.forEach((atom) => {
|
|
1706
|
+
const tokens = buildAtomSemanticTokens(atom);
|
|
1707
|
+
atomTokensById.set(atom.id, tokens);
|
|
1708
|
+
new Set(tokens).forEach((token) => {
|
|
1709
|
+
documentFrequency.set(token, (documentFrequency.get(token) || 0) + 1);
|
|
1710
|
+
});
|
|
1711
|
+
});
|
|
1712
|
+
const totalDocs = Math.max(1, params.atoms.length);
|
|
1713
|
+
const entriesByAtomId = new Map();
|
|
1714
|
+
atomTokensById.forEach((tokens, atomId) => {
|
|
1715
|
+
const frequency = buildTokenFrequency(tokens);
|
|
1716
|
+
const weights = buildTfIdfWeights(frequency, documentFrequency, totalDocs);
|
|
1717
|
+
const signaturePrefix = computeSimHashPrefix(computeWeightedSimHash(weights), LOCAL_VECTOR_ANN_SIGNATURE_PREFIX_BITS);
|
|
1718
|
+
entriesByAtomId.set(atomId, {
|
|
1719
|
+
atomId,
|
|
1720
|
+
tokens,
|
|
1721
|
+
weights,
|
|
1722
|
+
signaturePrefix,
|
|
1723
|
+
});
|
|
1724
|
+
});
|
|
1725
|
+
const annStructures = buildLocalVectorAnnStructures(entriesByAtomId);
|
|
1726
|
+
return {
|
|
1727
|
+
signature: params.signature,
|
|
1728
|
+
builtAt: params.builtAt,
|
|
1729
|
+
atomCount: params.atoms.length,
|
|
1730
|
+
documentFrequency,
|
|
1731
|
+
entriesByAtomId,
|
|
1732
|
+
tokenToAtomIds: annStructures.tokenToAtomIds,
|
|
1733
|
+
signatureBuckets: annStructures.signatureBuckets,
|
|
1734
|
+
loadedFromDisk: params.loadedFromDisk,
|
|
1735
|
+
persisted: params.persisted,
|
|
1736
|
+
};
|
|
1737
|
+
}
|
|
1738
|
+
buildSnapshot(index) {
|
|
1739
|
+
const entries = Array.from(index.entriesByAtomId.values())
|
|
1740
|
+
.map((entry) => ({
|
|
1741
|
+
atomId: entry.atomId,
|
|
1742
|
+
tokens: [...entry.tokens],
|
|
1743
|
+
weights: toSerializableWeightEntries(entry.weights),
|
|
1744
|
+
}))
|
|
1745
|
+
.sort((left, right) => left.atomId.localeCompare(right.atomId));
|
|
1746
|
+
const documentFrequency = Array.from(index.documentFrequency.entries())
|
|
1747
|
+
.map(([token, count]) => [token, Math.max(0, Math.floor(Number(count) || 0))])
|
|
1748
|
+
.filter(([token, count]) => Boolean(token) && count > 0)
|
|
1749
|
+
.sort((left, right) => left[0].localeCompare(right[0]));
|
|
1750
|
+
return {
|
|
1751
|
+
schemaVersion: LOCAL_VECTOR_INDEX_SCHEMA_VERSION,
|
|
1752
|
+
backendId: this.id,
|
|
1753
|
+
signature: index.signature,
|
|
1754
|
+
builtAt: index.builtAt,
|
|
1755
|
+
atomCount: index.atomCount,
|
|
1756
|
+
documentFrequency,
|
|
1757
|
+
entries,
|
|
1758
|
+
};
|
|
1759
|
+
}
|
|
1760
|
+
parseSnapshot(rawSnapshot) {
|
|
1761
|
+
if (!rawSnapshot || typeof rawSnapshot !== 'object') {
|
|
1762
|
+
return null;
|
|
1763
|
+
}
|
|
1764
|
+
const snapshot = rawSnapshot;
|
|
1765
|
+
if (Number(snapshot.schemaVersion) !== LOCAL_VECTOR_INDEX_SCHEMA_VERSION
|
|
1766
|
+
|| String(snapshot.backendId || '') !== this.id
|
|
1767
|
+
|| !Array.isArray(snapshot.entries)
|
|
1768
|
+
|| !Array.isArray(snapshot.documentFrequency)) {
|
|
1769
|
+
return null;
|
|
1770
|
+
}
|
|
1771
|
+
return {
|
|
1772
|
+
schemaVersion: LOCAL_VECTOR_INDEX_SCHEMA_VERSION,
|
|
1773
|
+
backendId: this.id,
|
|
1774
|
+
signature: String(snapshot.signature || '').trim(),
|
|
1775
|
+
builtAt: String(snapshot.builtAt || '').trim(),
|
|
1776
|
+
atomCount: Math.max(0, Math.floor(Number(snapshot.atomCount || 0))),
|
|
1777
|
+
documentFrequency: snapshot.documentFrequency,
|
|
1778
|
+
entries: snapshot.entries,
|
|
1779
|
+
};
|
|
1780
|
+
}
|
|
1781
|
+
snapshotToIndex(snapshot) {
|
|
1782
|
+
const documentFrequency = new Map();
|
|
1783
|
+
snapshot.documentFrequency.forEach((entry) => {
|
|
1784
|
+
if (!Array.isArray(entry) || entry.length < 2) {
|
|
1785
|
+
return;
|
|
1786
|
+
}
|
|
1787
|
+
const token = String(entry[0] || '').trim().toLowerCase();
|
|
1788
|
+
const count = Math.max(0, Math.floor(Number(entry[1]) || 0));
|
|
1789
|
+
if (!token || count <= 0) {
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1792
|
+
documentFrequency.set(token, count);
|
|
1793
|
+
});
|
|
1794
|
+
const entriesByAtomId = new Map();
|
|
1795
|
+
snapshot.entries.forEach((entry) => {
|
|
1796
|
+
if (!entry || typeof entry !== 'object') {
|
|
1797
|
+
return;
|
|
1798
|
+
}
|
|
1799
|
+
const atomId = String(entry.atomId || '').trim();
|
|
1800
|
+
if (!atomId) {
|
|
1801
|
+
return;
|
|
1802
|
+
}
|
|
1803
|
+
const tokens = Array.isArray(entry.tokens)
|
|
1804
|
+
? uniqueTokens(entry.tokens.map((token) => stemSemanticToken(token)).filter((token) => token.length > 0))
|
|
1805
|
+
: [];
|
|
1806
|
+
const weights = toWeightMap(entry.weights);
|
|
1807
|
+
const signaturePrefix = computeSimHashPrefix(computeWeightedSimHash(weights), LOCAL_VECTOR_ANN_SIGNATURE_PREFIX_BITS);
|
|
1808
|
+
entriesByAtomId.set(atomId, {
|
|
1809
|
+
atomId,
|
|
1810
|
+
tokens,
|
|
1811
|
+
weights,
|
|
1812
|
+
signaturePrefix,
|
|
1813
|
+
});
|
|
1814
|
+
});
|
|
1815
|
+
const annStructures = buildLocalVectorAnnStructures(entriesByAtomId);
|
|
1816
|
+
return {
|
|
1817
|
+
signature: snapshot.signature,
|
|
1818
|
+
builtAt: snapshot.builtAt || new Date().toISOString(),
|
|
1819
|
+
atomCount: Math.max(snapshot.atomCount, entriesByAtomId.size),
|
|
1820
|
+
documentFrequency,
|
|
1821
|
+
entriesByAtomId,
|
|
1822
|
+
tokenToAtomIds: annStructures.tokenToAtomIds,
|
|
1823
|
+
signatureBuckets: annStructures.signatureBuckets,
|
|
1824
|
+
loadedFromDisk: true,
|
|
1825
|
+
persisted: true,
|
|
1826
|
+
};
|
|
1827
|
+
}
|
|
1828
|
+
async tryLoadIndexFromDisk(signature) {
|
|
1829
|
+
if (!this.localVectorIndexPath) {
|
|
1830
|
+
return null;
|
|
1831
|
+
}
|
|
1832
|
+
try {
|
|
1833
|
+
const content = await fs.promises.readFile(this.localVectorIndexPath, 'utf8');
|
|
1834
|
+
const parsedSnapshot = this.parseSnapshot(JSON.parse(content));
|
|
1835
|
+
if (!parsedSnapshot || parsedSnapshot.signature !== signature) {
|
|
1836
|
+
return null;
|
|
1837
|
+
}
|
|
1838
|
+
const index = this.snapshotToIndex(parsedSnapshot);
|
|
1839
|
+
return index;
|
|
1840
|
+
}
|
|
1841
|
+
catch (error) {
|
|
1842
|
+
const code = error?.code;
|
|
1843
|
+
if (code === 'ENOENT' || code === 'ENOTDIR') {
|
|
1844
|
+
return null;
|
|
1845
|
+
}
|
|
1846
|
+
this.lastError = String(error?.message || error);
|
|
1847
|
+
return null;
|
|
1848
|
+
}
|
|
1849
|
+
}
|
|
1850
|
+
async tryPersistIndexToDisk(index) {
|
|
1851
|
+
if (!this.localVectorIndexPath) {
|
|
1852
|
+
return false;
|
|
1853
|
+
}
|
|
1854
|
+
const resolvedPath = path.resolve(this.localVectorIndexPath);
|
|
1855
|
+
const directory = path.dirname(resolvedPath);
|
|
1856
|
+
const tempPath = `${resolvedPath}.tmp`;
|
|
1857
|
+
try {
|
|
1858
|
+
await fs.promises.mkdir(directory, { recursive: true });
|
|
1859
|
+
await fs.promises.writeFile(tempPath, JSON.stringify(this.buildSnapshot(index), null, 2), 'utf8');
|
|
1860
|
+
await fs.promises.rename(tempPath, resolvedPath);
|
|
1861
|
+
return true;
|
|
1862
|
+
}
|
|
1863
|
+
catch (error) {
|
|
1864
|
+
this.lastError = String(error?.message || error);
|
|
1865
|
+
return false;
|
|
1866
|
+
}
|
|
1867
|
+
finally {
|
|
1868
|
+
try {
|
|
1869
|
+
await fs.promises.unlink(tempPath);
|
|
1870
|
+
}
|
|
1871
|
+
catch (_cleanupError) {
|
|
1872
|
+
}
|
|
1873
|
+
}
|
|
1874
|
+
}
|
|
1875
|
+
}
|
|
1876
|
+
exports.LocalVectorGraphQueryBackend = LocalVectorGraphQueryBackend;
|
|
1877
|
+
function normalizeGraphQueryBackendType(rawValue) {
|
|
1878
|
+
const normalized = String(rawValue || '').trim().toLowerCase();
|
|
1879
|
+
if (normalized === 'keyword_only' || normalized === 'keyword-only' || normalized === 'keyword') {
|
|
1880
|
+
return 'keyword_only';
|
|
1881
|
+
}
|
|
1882
|
+
if (normalized === 'local_vector'
|
|
1883
|
+
|| normalized === 'local-vector'
|
|
1884
|
+
|| normalized === 'vector'
|
|
1885
|
+
|| normalized === 'semantic_vector'
|
|
1886
|
+
|| normalized === 'semantic-vector') {
|
|
1887
|
+
return 'local_vector';
|
|
1888
|
+
}
|
|
1889
|
+
return 'local_hybrid';
|
|
1890
|
+
}
|
|
1891
|
+
function normalizeLocalVectorAccelerationFailureMode(rawValue) {
|
|
1892
|
+
const normalized = String(rawValue || '').trim().toLowerCase();
|
|
1893
|
+
if (normalized === 'fail_closed'
|
|
1894
|
+
|| normalized === 'fail-closed'
|
|
1895
|
+
|| normalized === 'strict'
|
|
1896
|
+
|| normalized === 'closed') {
|
|
1897
|
+
return 'fail_closed';
|
|
1898
|
+
}
|
|
1899
|
+
return 'fail_open';
|
|
1900
|
+
}
|
|
1901
|
+
function createGraphQueryBackend(options = {}) {
|
|
1902
|
+
const backend = normalizeGraphQueryBackendType(options.backend);
|
|
1903
|
+
if (backend === 'keyword_only') {
|
|
1904
|
+
return new KeywordOnlyGraphQueryBackend();
|
|
1905
|
+
}
|
|
1906
|
+
if (backend === 'local_vector') {
|
|
1907
|
+
return new LocalVectorGraphQueryBackend({
|
|
1908
|
+
localVectorIndexPath: options.localVectorIndexPath,
|
|
1909
|
+
localVectorAnnPrefilterEnabled: options.localVectorAnnPrefilterEnabled,
|
|
1910
|
+
localVectorAccelerationAdapter: options.localVectorAccelerationAdapter,
|
|
1911
|
+
localVectorAccelerationFailureMode: normalizeLocalVectorAccelerationFailureMode(options.localVectorAccelerationFailureMode),
|
|
1912
|
+
localVectorAccelerationRepresentationStrict: options.localVectorAccelerationRepresentationStrict === true,
|
|
1913
|
+
});
|
|
1914
|
+
}
|
|
1915
|
+
return new LocalHybridGraphQueryBackend();
|
|
1916
|
+
}
|
|
1917
|
+
function listGraphQueryBackendCatalog() {
|
|
1918
|
+
return GRAPH_QUERY_BACKEND_CATALOG.map((item) => ({
|
|
1919
|
+
...item,
|
|
1920
|
+
aliases: [...item.aliases],
|
|
1921
|
+
}));
|
|
1922
|
+
}
|