@framers/agentos 0.1.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 +98 -0
- package/README.md +576 -0
- package/dist/api/AgentOS.d.ts +451 -0
- package/dist/api/AgentOS.d.ts.map +1 -0
- package/dist/api/AgentOS.js +1157 -0
- package/dist/api/AgentOS.js.map +1 -0
- package/dist/api/AgentOSOrchestrator.d.ts +157 -0
- package/dist/api/AgentOSOrchestrator.d.ts.map +1 -0
- package/dist/api/AgentOSOrchestrator.js +679 -0
- package/dist/api/AgentOSOrchestrator.js.map +1 -0
- package/dist/api/interfaces/IAgentOS.d.ts +138 -0
- package/dist/api/interfaces/IAgentOS.d.ts.map +1 -0
- package/dist/api/interfaces/IAgentOS.js +11 -0
- package/dist/api/interfaces/IAgentOS.js.map +1 -0
- package/dist/api/interfaces/IUnifiedAgent.d.ts +126 -0
- package/dist/api/interfaces/IUnifiedAgent.d.ts.map +1 -0
- package/dist/api/interfaces/IUnifiedAgent.js +3 -0
- package/dist/api/interfaces/IUnifiedAgent.js.map +1 -0
- package/dist/api/types/AgentOSInput.d.ts +114 -0
- package/dist/api/types/AgentOSInput.d.ts.map +1 -0
- package/dist/api/types/AgentOSInput.js +13 -0
- package/dist/api/types/AgentOSInput.js.map +1 -0
- package/dist/api/types/AgentOSResponse.d.ts +170 -0
- package/dist/api/types/AgentOSResponse.d.ts.map +1 -0
- package/dist/api/types/AgentOSResponse.js +25 -0
- package/dist/api/types/AgentOSResponse.js.map +1 -0
- package/dist/cognitive_substrate/GMI.d.ts +148 -0
- package/dist/cognitive_substrate/GMI.d.ts.map +1 -0
- package/dist/cognitive_substrate/GMI.js +1003 -0
- package/dist/cognitive_substrate/GMI.js.map +1 -0
- package/dist/cognitive_substrate/GMIManager.d.ts +98 -0
- package/dist/cognitive_substrate/GMIManager.d.ts.map +1 -0
- package/dist/cognitive_substrate/GMIManager.js +517 -0
- package/dist/cognitive_substrate/GMIManager.js.map +1 -0
- package/dist/cognitive_substrate/IGMI.d.ts +469 -0
- package/dist/cognitive_substrate/IGMI.d.ts.map +1 -0
- package/dist/cognitive_substrate/IGMI.js +111 -0
- package/dist/cognitive_substrate/IGMI.js.map +1 -0
- package/dist/cognitive_substrate/memory/IWorkingMemory.d.ts +139 -0
- package/dist/cognitive_substrate/memory/IWorkingMemory.d.ts.map +1 -0
- package/dist/cognitive_substrate/memory/IWorkingMemory.js +14 -0
- package/dist/cognitive_substrate/memory/IWorkingMemory.js.map +1 -0
- package/dist/cognitive_substrate/memory/InMemoryWorkingMemory.d.ts +143 -0
- package/dist/cognitive_substrate/memory/InMemoryWorkingMemory.d.ts.map +1 -0
- package/dist/cognitive_substrate/memory/InMemoryWorkingMemory.js +186 -0
- package/dist/cognitive_substrate/memory/InMemoryWorkingMemory.js.map +1 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayManager.d.ts +33 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayManager.d.ts.map +1 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayManager.js +138 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayManager.js.map +1 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayTypes.d.ts +32 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayTypes.d.ts.map +1 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayTypes.js +2 -0
- package/dist/cognitive_substrate/persona_overlays/PersonaOverlayTypes.js.map +1 -0
- package/dist/cognitive_substrate/personas/IPersonaDefinition.d.ts +336 -0
- package/dist/cognitive_substrate/personas/IPersonaDefinition.d.ts.map +1 -0
- package/dist/cognitive_substrate/personas/IPersonaDefinition.js +8 -0
- package/dist/cognitive_substrate/personas/IPersonaDefinition.js.map +1 -0
- package/dist/cognitive_substrate/personas/IPersonaLoader.d.ts +78 -0
- package/dist/cognitive_substrate/personas/IPersonaLoader.d.ts.map +1 -0
- package/dist/cognitive_substrate/personas/IPersonaLoader.js +9 -0
- package/dist/cognitive_substrate/personas/IPersonaLoader.js.map +1 -0
- package/dist/cognitive_substrate/personas/PersonaLoader.d.ts +60 -0
- package/dist/cognitive_substrate/personas/PersonaLoader.d.ts.map +1 -0
- package/dist/cognitive_substrate/personas/PersonaLoader.js +138 -0
- package/dist/cognitive_substrate/personas/PersonaLoader.js.map +1 -0
- package/dist/cognitive_substrate/personas/PersonaValidation.d.ts +139 -0
- package/dist/cognitive_substrate/personas/PersonaValidation.d.ts.map +1 -0
- package/dist/cognitive_substrate/personas/PersonaValidation.js +277 -0
- package/dist/cognitive_substrate/personas/PersonaValidation.js.map +1 -0
- package/dist/cognitive_substrate/personas/definitions/atlas_systems_architect.json +29 -0
- package/dist/cognitive_substrate/personas/definitions/default_assistant_persona.json +346 -0
- package/dist/cognitive_substrate/personas/definitions/default_free_assistant.json +13 -0
- package/dist/cognitive_substrate/personas/definitions/index.d.ts +14 -0
- package/dist/cognitive_substrate/personas/definitions/index.d.ts.map +1 -0
- package/dist/cognitive_substrate/personas/definitions/index.js +35 -0
- package/dist/cognitive_substrate/personas/definitions/index.js.map +1 -0
- package/dist/cognitive_substrate/personas/definitions/nerf_generalist.json +11 -0
- package/dist/cognitive_substrate/personas/definitions/v_researcher.json +11 -0
- package/dist/config/AgentOSConfig.d.ts +74 -0
- package/dist/config/AgentOSConfig.d.ts.map +1 -0
- package/dist/config/AgentOSConfig.js +399 -0
- package/dist/config/AgentOSConfig.js.map +1 -0
- package/dist/config/EmbeddingManagerConfiguration.d.ts +190 -0
- package/dist/config/EmbeddingManagerConfiguration.d.ts.map +1 -0
- package/dist/config/EmbeddingManagerConfiguration.js +16 -0
- package/dist/config/EmbeddingManagerConfiguration.js.map +1 -0
- package/dist/config/MemoryLifecycleManagerConfiguration.d.ts +165 -0
- package/dist/config/MemoryLifecycleManagerConfiguration.d.ts.map +1 -0
- package/dist/config/MemoryLifecycleManagerConfiguration.js +69 -0
- package/dist/config/MemoryLifecycleManagerConfiguration.js.map +1 -0
- package/dist/config/RetrievalAugmentorConfiguration.d.ts +98 -0
- package/dist/config/RetrievalAugmentorConfiguration.d.ts.map +1 -0
- package/dist/config/RetrievalAugmentorConfiguration.js +47 -0
- package/dist/config/RetrievalAugmentorConfiguration.js.map +1 -0
- package/dist/config/ToolOrchestratorConfig.d.ts +69 -0
- package/dist/config/ToolOrchestratorConfig.d.ts.map +1 -0
- package/dist/config/ToolOrchestratorConfig.js +11 -0
- package/dist/config/ToolOrchestratorConfig.js.map +1 -0
- package/dist/config/VectorStoreConfiguration.d.ts +223 -0
- package/dist/config/VectorStoreConfiguration.d.ts.map +1 -0
- package/dist/config/VectorStoreConfiguration.js +59 -0
- package/dist/config/VectorStoreConfiguration.js.map +1 -0
- package/dist/config/extension-secrets.json +38 -0
- package/dist/config/extensionSecrets.d.ts +13 -0
- package/dist/config/extensionSecrets.d.ts.map +1 -0
- package/dist/config/extensionSecrets.js +24 -0
- package/dist/config/extensionSecrets.js.map +1 -0
- package/dist/core/agency/AgencyMemoryManager.d.ts +300 -0
- package/dist/core/agency/AgencyMemoryManager.d.ts.map +1 -0
- package/dist/core/agency/AgencyMemoryManager.js +657 -0
- package/dist/core/agency/AgencyMemoryManager.js.map +1 -0
- package/dist/core/agency/AgencyRegistry.d.ts +100 -0
- package/dist/core/agency/AgencyRegistry.d.ts.map +1 -0
- package/dist/core/agency/AgencyRegistry.js +209 -0
- package/dist/core/agency/AgencyRegistry.js.map +1 -0
- package/dist/core/agency/AgencyTypes.d.ts +200 -0
- package/dist/core/agency/AgencyTypes.d.ts.map +1 -0
- package/dist/core/agency/AgencyTypes.js +7 -0
- package/dist/core/agency/AgencyTypes.js.map +1 -0
- package/dist/core/agency/AgentCommunicationBus.d.ts +150 -0
- package/dist/core/agency/AgentCommunicationBus.d.ts.map +1 -0
- package/dist/core/agency/AgentCommunicationBus.js +568 -0
- package/dist/core/agency/AgentCommunicationBus.js.map +1 -0
- package/dist/core/agency/IAgentCommunicationBus.d.ts +469 -0
- package/dist/core/agency/IAgentCommunicationBus.d.ts.map +1 -0
- package/dist/core/agency/IAgentCommunicationBus.js +40 -0
- package/dist/core/agency/IAgentCommunicationBus.js.map +1 -0
- package/dist/core/agency/index.d.ts +18 -0
- package/dist/core/agency/index.d.ts.map +1 -0
- package/dist/core/agency/index.js +18 -0
- package/dist/core/agency/index.js.map +1 -0
- package/dist/core/agents/AgentCore.d.ts +385 -0
- package/dist/core/agents/AgentCore.d.ts.map +1 -0
- package/dist/core/agents/AgentCore.js +527 -0
- package/dist/core/agents/AgentCore.js.map +1 -0
- package/dist/core/agents/AgentFactory.d.ts +123 -0
- package/dist/core/agents/AgentFactory.d.ts.map +1 -0
- package/dist/core/agents/AgentFactory.js +232 -0
- package/dist/core/agents/AgentFactory.js.map +1 -0
- package/dist/core/agents/AgentPoolAgent.d.ts +244 -0
- package/dist/core/agents/AgentPoolAgent.d.ts.map +1 -0
- package/dist/core/agents/AgentPoolAgent.js +697 -0
- package/dist/core/agents/AgentPoolAgent.js.map +1 -0
- package/dist/core/agents/AgentPoolConfig.d.ts +191 -0
- package/dist/core/agents/AgentPoolConfig.d.ts.map +1 -0
- package/dist/core/agents/AgentPoolConfig.js +58 -0
- package/dist/core/agents/AgentPoolConfig.js.map +1 -0
- package/dist/core/agents/IAgent.d.ts +226 -0
- package/dist/core/agents/IAgent.d.ts.map +1 -0
- package/dist/core/agents/IAgent.js +14 -0
- package/dist/core/agents/IAgent.js.map +1 -0
- package/dist/core/agents/IAgentFactory.d.ts +137 -0
- package/dist/core/agents/IAgentFactory.d.ts.map +1 -0
- package/dist/core/agents/IAgentFactory.js +13 -0
- package/dist/core/agents/IAgentFactory.js.map +1 -0
- package/dist/core/agents/tools/Tool.d.ts +17 -0
- package/dist/core/agents/tools/Tool.d.ts.map +1 -0
- package/dist/core/agents/tools/Tool.js +8 -0
- package/dist/core/agents/tools/Tool.js.map +1 -0
- package/dist/core/ai_utilities/HybridUtilityAI.d.ts +1 -0
- package/dist/core/ai_utilities/HybridUtilityAI.d.ts.map +1 -0
- package/dist/core/ai_utilities/HybridUtilityAI.js +2 -0
- package/dist/core/ai_utilities/HybridUtilityAI.js.map +1 -0
- package/dist/core/ai_utilities/IUtilityAI.d.ts +212 -0
- package/dist/core/ai_utilities/IUtilityAI.d.ts.map +1 -0
- package/dist/core/ai_utilities/IUtilityAI.js +11 -0
- package/dist/core/ai_utilities/IUtilityAI.js.map +1 -0
- package/dist/core/ai_utilities/LLMUtilityAI.d.ts +94 -0
- package/dist/core/ai_utilities/LLMUtilityAI.d.ts.map +1 -0
- package/dist/core/ai_utilities/LLMUtilityAI.js +434 -0
- package/dist/core/ai_utilities/LLMUtilityAI.js.map +1 -0
- package/dist/core/ai_utilities/StatisticalUtilityAI.d.ts +102 -0
- package/dist/core/ai_utilities/StatisticalUtilityAI.d.ts.map +1 -0
- package/dist/core/ai_utilities/StatisticalUtilityAI.js +617 -0
- package/dist/core/ai_utilities/StatisticalUtilityAI.js.map +1 -0
- package/dist/core/conversation/ConversationContext.d.ts +259 -0
- package/dist/core/conversation/ConversationContext.d.ts.map +1 -0
- package/dist/core/conversation/ConversationContext.js +450 -0
- package/dist/core/conversation/ConversationContext.js.map +1 -0
- package/dist/core/conversation/ConversationManager.d.ts +223 -0
- package/dist/core/conversation/ConversationManager.d.ts.map +1 -0
- package/dist/core/conversation/ConversationManager.js +558 -0
- package/dist/core/conversation/ConversationManager.js.map +1 -0
- package/dist/core/conversation/ConversationMessage.d.ts +184 -0
- package/dist/core/conversation/ConversationMessage.d.ts.map +1 -0
- package/dist/core/conversation/ConversationMessage.js +66 -0
- package/dist/core/conversation/ConversationMessage.js.map +1 -0
- package/dist/core/evaluation/Evaluator.d.ts +28 -0
- package/dist/core/evaluation/Evaluator.d.ts.map +1 -0
- package/dist/core/evaluation/Evaluator.js +490 -0
- package/dist/core/evaluation/Evaluator.js.map +1 -0
- package/dist/core/evaluation/IEvaluator.d.ts +309 -0
- package/dist/core/evaluation/IEvaluator.d.ts.map +1 -0
- package/dist/core/evaluation/IEvaluator.js +12 -0
- package/dist/core/evaluation/IEvaluator.js.map +1 -0
- package/dist/core/evaluation/LLMJudge.d.ts +105 -0
- package/dist/core/evaluation/LLMJudge.d.ts.map +1 -0
- package/dist/core/evaluation/LLMJudge.js +229 -0
- package/dist/core/evaluation/LLMJudge.js.map +1 -0
- package/dist/core/evaluation/index.d.ts +9 -0
- package/dist/core/evaluation/index.d.ts.map +1 -0
- package/dist/core/evaluation/index.js +9 -0
- package/dist/core/evaluation/index.js.map +1 -0
- package/dist/core/guardrails/IGuardrailService.d.ts +142 -0
- package/dist/core/guardrails/IGuardrailService.d.ts.map +1 -0
- package/dist/core/guardrails/IGuardrailService.js +24 -0
- package/dist/core/guardrails/IGuardrailService.js.map +1 -0
- package/dist/core/guardrails/guardrailDispatcher.d.ts +36 -0
- package/dist/core/guardrails/guardrailDispatcher.d.ts.map +1 -0
- package/dist/core/guardrails/guardrailDispatcher.js +240 -0
- package/dist/core/guardrails/guardrailDispatcher.js.map +1 -0
- package/dist/core/hitl/HumanInteractionManager.d.ts +146 -0
- package/dist/core/hitl/HumanInteractionManager.d.ts.map +1 -0
- package/dist/core/hitl/HumanInteractionManager.js +491 -0
- package/dist/core/hitl/HumanInteractionManager.js.map +1 -0
- package/dist/core/hitl/IHumanInteractionManager.d.ts +521 -0
- package/dist/core/hitl/IHumanInteractionManager.d.ts.map +1 -0
- package/dist/core/hitl/IHumanInteractionManager.js +33 -0
- package/dist/core/hitl/IHumanInteractionManager.js.map +1 -0
- package/dist/core/hitl/index.d.ts +17 -0
- package/dist/core/hitl/index.d.ts.map +1 -0
- package/dist/core/hitl/index.js +17 -0
- package/dist/core/hitl/index.js.map +1 -0
- package/dist/core/knowledge/IKnowledgeGraph.d.ts +351 -0
- package/dist/core/knowledge/IKnowledgeGraph.d.ts.map +1 -0
- package/dist/core/knowledge/IKnowledgeGraph.js +10 -0
- package/dist/core/knowledge/IKnowledgeGraph.js.map +1 -0
- package/dist/core/knowledge/KnowledgeGraph.d.ts +93 -0
- package/dist/core/knowledge/KnowledgeGraph.d.ts.map +1 -0
- package/dist/core/knowledge/KnowledgeGraph.js +601 -0
- package/dist/core/knowledge/KnowledgeGraph.js.map +1 -0
- package/dist/core/knowledge/index.d.ts +8 -0
- package/dist/core/knowledge/index.d.ts.map +1 -0
- package/dist/core/knowledge/index.js +8 -0
- package/dist/core/knowledge/index.js.map +1 -0
- package/dist/core/language/LanguageService.d.ts +77 -0
- package/dist/core/language/LanguageService.d.ts.map +1 -0
- package/dist/core/language/LanguageService.js +305 -0
- package/dist/core/language/LanguageService.js.map +1 -0
- package/dist/core/language/index.d.ts +6 -0
- package/dist/core/language/index.d.ts.map +1 -0
- package/dist/core/language/index.js +6 -0
- package/dist/core/language/index.js.map +1 -0
- package/dist/core/language/interfaces.d.ts +168 -0
- package/dist/core/language/interfaces.d.ts.map +1 -0
- package/dist/core/language/interfaces.js +37 -0
- package/dist/core/language/interfaces.js.map +1 -0
- package/dist/core/language/providers/DeepLTranslationProvider.d.ts +16 -0
- package/dist/core/language/providers/DeepLTranslationProvider.d.ts.map +1 -0
- package/dist/core/language/providers/DeepLTranslationProvider.js +28 -0
- package/dist/core/language/providers/DeepLTranslationProvider.js.map +1 -0
- package/dist/core/language/providers/OpenAITranslationProvider.d.ts +17 -0
- package/dist/core/language/providers/OpenAITranslationProvider.d.ts.map +1 -0
- package/dist/core/language/providers/OpenAITranslationProvider.js +34 -0
- package/dist/core/language/providers/OpenAITranslationProvider.js.map +1 -0
- package/dist/core/language/providers/WhisperDetectionProvider.d.ts +16 -0
- package/dist/core/language/providers/WhisperDetectionProvider.d.ts.map +1 -0
- package/dist/core/language/providers/WhisperDetectionProvider.js +15 -0
- package/dist/core/language/providers/WhisperDetectionProvider.js.map +1 -0
- package/dist/core/llm/IPromptEngine.d.ts +627 -0
- package/dist/core/llm/IPromptEngine.d.ts.map +1 -0
- package/dist/core/llm/IPromptEngine.js +81 -0
- package/dist/core/llm/IPromptEngine.js.map +1 -0
- package/dist/core/llm/PromptEngine.d.ts +108 -0
- package/dist/core/llm/PromptEngine.d.ts.map +1 -0
- package/dist/core/llm/PromptEngine.js +872 -0
- package/dist/core/llm/PromptEngine.js.map +1 -0
- package/dist/core/llm/providers/AIModelProviderManager.d.ts +74 -0
- package/dist/core/llm/providers/AIModelProviderManager.d.ts.map +1 -0
- package/dist/core/llm/providers/AIModelProviderManager.js +263 -0
- package/dist/core/llm/providers/AIModelProviderManager.js.map +1 -0
- package/dist/core/llm/providers/IProvider.d.ts +327 -0
- package/dist/core/llm/providers/IProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/IProvider.js +39 -0
- package/dist/core/llm/providers/IProvider.js.map +1 -0
- package/dist/core/llm/providers/errors/OllamaProviderError.d.ts +36 -0
- package/dist/core/llm/providers/errors/OllamaProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/OllamaProviderError.js +40 -0
- package/dist/core/llm/providers/errors/OllamaProviderError.js.map +1 -0
- package/dist/core/llm/providers/errors/OpenAIProviderError.d.ts +42 -0
- package/dist/core/llm/providers/errors/OpenAIProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/OpenAIProviderError.js +44 -0
- package/dist/core/llm/providers/errors/OpenAIProviderError.js.map +1 -0
- package/dist/core/llm/providers/errors/OpenRouterProviderError.d.ts +39 -0
- package/dist/core/llm/providers/errors/OpenRouterProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/OpenRouterProviderError.js +42 -0
- package/dist/core/llm/providers/errors/OpenRouterProviderError.js.map +1 -0
- package/dist/core/llm/providers/errors/ProviderError.d.ts +37 -0
- package/dist/core/llm/providers/errors/ProviderError.d.ts.map +1 -0
- package/dist/core/llm/providers/errors/ProviderError.js +36 -0
- package/dist/core/llm/providers/errors/ProviderError.js.map +1 -0
- package/dist/core/llm/providers/implementations/OllamaProvider.d.ts +80 -0
- package/dist/core/llm/providers/implementations/OllamaProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/OllamaProvider.js +473 -0
- package/dist/core/llm/providers/implementations/OllamaProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts +160 -0
- package/dist/core/llm/providers/implementations/OpenAIProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/OpenAIProvider.js +672 -0
- package/dist/core/llm/providers/implementations/OpenAIProvider.js.map +1 -0
- package/dist/core/llm/providers/implementations/OpenRouterProvider.d.ts +51 -0
- package/dist/core/llm/providers/implementations/OpenRouterProvider.d.ts.map +1 -0
- package/dist/core/llm/providers/implementations/OpenRouterProvider.js +499 -0
- package/dist/core/llm/providers/implementations/OpenRouterProvider.js.map +1 -0
- package/dist/core/llm/routing/IModelRouter.d.ts +129 -0
- package/dist/core/llm/routing/IModelRouter.d.ts.map +1 -0
- package/dist/core/llm/routing/IModelRouter.js +14 -0
- package/dist/core/llm/routing/IModelRouter.js.map +1 -0
- package/dist/core/llm/routing/ModelRouter.d.ts +157 -0
- package/dist/core/llm/routing/ModelRouter.d.ts.map +1 -0
- package/dist/core/llm/routing/ModelRouter.js +190 -0
- package/dist/core/llm/routing/ModelRouter.js.map +1 -0
- package/dist/core/llm/streaming/StreamingBatcher.d.ts +54 -0
- package/dist/core/llm/streaming/StreamingBatcher.d.ts.map +1 -0
- package/dist/core/llm/streaming/StreamingBatcher.js +173 -0
- package/dist/core/llm/streaming/StreamingBatcher.js.map +1 -0
- package/dist/core/llm/streaming/StreamingReconstructor.d.ts +69 -0
- package/dist/core/llm/streaming/StreamingReconstructor.d.ts.map +1 -0
- package/dist/core/llm/streaming/StreamingReconstructor.js +102 -0
- package/dist/core/llm/streaming/StreamingReconstructor.js.map +1 -0
- package/dist/core/marketplace/IMarketplace.d.ts +500 -0
- package/dist/core/marketplace/IMarketplace.d.ts.map +1 -0
- package/dist/core/marketplace/IMarketplace.js +10 -0
- package/dist/core/marketplace/IMarketplace.js.map +1 -0
- package/dist/core/marketplace/Marketplace.d.ts +122 -0
- package/dist/core/marketplace/Marketplace.d.ts.map +1 -0
- package/dist/core/marketplace/Marketplace.js +591 -0
- package/dist/core/marketplace/Marketplace.js.map +1 -0
- package/dist/core/marketplace/index.d.ts +8 -0
- package/dist/core/marketplace/index.d.ts.map +1 -0
- package/dist/core/marketplace/index.js +8 -0
- package/dist/core/marketplace/index.js.map +1 -0
- package/dist/core/observability/ITracer.d.ts +317 -0
- package/dist/core/observability/ITracer.d.ts.map +1 -0
- package/dist/core/observability/ITracer.js +55 -0
- package/dist/core/observability/ITracer.js.map +1 -0
- package/dist/core/observability/Tracer.d.ts +76 -0
- package/dist/core/observability/Tracer.d.ts.map +1 -0
- package/dist/core/observability/Tracer.js +360 -0
- package/dist/core/observability/Tracer.js.map +1 -0
- package/dist/core/observability/index.d.ts +9 -0
- package/dist/core/observability/index.d.ts.map +1 -0
- package/dist/core/observability/index.js +8 -0
- package/dist/core/observability/index.js.map +1 -0
- package/dist/core/orchestration/AgentOrchestrator.d.ts +243 -0
- package/dist/core/orchestration/AgentOrchestrator.d.ts.map +1 -0
- package/dist/core/orchestration/AgentOrchestrator.js +648 -0
- package/dist/core/orchestration/AgentOrchestrator.js.map +1 -0
- package/dist/core/orchestration/IAgentOrchestrator.d.ts +44 -0
- package/dist/core/orchestration/IAgentOrchestrator.d.ts.map +1 -0
- package/dist/core/orchestration/IAgentOrchestrator.js +4 -0
- package/dist/core/orchestration/IAgentOrchestrator.js.map +1 -0
- package/dist/core/orchestration/helpers.d.ts +12 -0
- package/dist/core/orchestration/helpers.d.ts.map +1 -0
- package/dist/core/orchestration/helpers.js +36 -0
- package/dist/core/orchestration/helpers.js.map +1 -0
- package/dist/core/planning/IPlanningEngine.d.ts +524 -0
- package/dist/core/planning/IPlanningEngine.d.ts.map +1 -0
- package/dist/core/planning/IPlanningEngine.js +32 -0
- package/dist/core/planning/IPlanningEngine.js.map +1 -0
- package/dist/core/planning/PlanningEngine.d.ts +161 -0
- package/dist/core/planning/PlanningEngine.d.ts.map +1 -0
- package/dist/core/planning/PlanningEngine.js +783 -0
- package/dist/core/planning/PlanningEngine.js.map +1 -0
- package/dist/core/planning/index.d.ts +25 -0
- package/dist/core/planning/index.d.ts.map +1 -0
- package/dist/core/planning/index.js +25 -0
- package/dist/core/planning/index.js.map +1 -0
- package/dist/core/sandbox/CodeSandbox.d.ts +86 -0
- package/dist/core/sandbox/CodeSandbox.d.ts.map +1 -0
- package/dist/core/sandbox/CodeSandbox.js +475 -0
- package/dist/core/sandbox/CodeSandbox.js.map +1 -0
- package/dist/core/sandbox/ICodeSandbox.d.ts +249 -0
- package/dist/core/sandbox/ICodeSandbox.d.ts.map +1 -0
- package/dist/core/sandbox/ICodeSandbox.js +24 -0
- package/dist/core/sandbox/ICodeSandbox.js.map +1 -0
- package/dist/core/sandbox/index.d.ts +9 -0
- package/dist/core/sandbox/index.d.ts.map +1 -0
- package/dist/core/sandbox/index.js +8 -0
- package/dist/core/sandbox/index.js.map +1 -0
- package/dist/core/storage/IStorageAdapter.d.ts +483 -0
- package/dist/core/storage/IStorageAdapter.d.ts.map +1 -0
- package/dist/core/storage/IStorageAdapter.js +19 -0
- package/dist/core/storage/IStorageAdapter.js.map +1 -0
- package/dist/core/storage/InMemoryStorageAdapter.d.ts +192 -0
- package/dist/core/storage/InMemoryStorageAdapter.d.ts.map +1 -0
- package/dist/core/storage/InMemoryStorageAdapter.js +343 -0
- package/dist/core/storage/InMemoryStorageAdapter.js.map +1 -0
- package/dist/core/storage/SqlStorageAdapter.d.ts +262 -0
- package/dist/core/storage/SqlStorageAdapter.d.ts.map +1 -0
- package/dist/core/storage/SqlStorageAdapter.js +485 -0
- package/dist/core/storage/SqlStorageAdapter.js.map +1 -0
- package/dist/core/storage/index.d.ts +14 -0
- package/dist/core/storage/index.d.ts.map +1 -0
- package/dist/core/storage/index.js +14 -0
- package/dist/core/storage/index.js.map +1 -0
- package/dist/core/streaming/IStreamClient.d.ts +72 -0
- package/dist/core/streaming/IStreamClient.d.ts.map +1 -0
- package/dist/core/streaming/IStreamClient.js +12 -0
- package/dist/core/streaming/IStreamClient.js.map +1 -0
- package/dist/core/streaming/StreamingManager.d.ts +242 -0
- package/dist/core/streaming/StreamingManager.d.ts.map +1 -0
- package/dist/core/streaming/StreamingManager.js +282 -0
- package/dist/core/streaming/StreamingManager.js.map +1 -0
- package/dist/core/structured/IStructuredOutputManager.d.ts +701 -0
- package/dist/core/structured/IStructuredOutputManager.d.ts.map +1 -0
- package/dist/core/structured/IStructuredOutputManager.js +74 -0
- package/dist/core/structured/IStructuredOutputManager.js.map +1 -0
- package/dist/core/structured/StructuredOutputManager.d.ts +140 -0
- package/dist/core/structured/StructuredOutputManager.d.ts.map +1 -0
- package/dist/core/structured/StructuredOutputManager.js +1015 -0
- package/dist/core/structured/StructuredOutputManager.js.map +1 -0
- package/dist/core/structured/index.d.ts +34 -0
- package/dist/core/structured/index.d.ts.map +1 -0
- package/dist/core/structured/index.js +34 -0
- package/dist/core/structured/index.js.map +1 -0
- package/dist/core/tools/ITool.d.ts +228 -0
- package/dist/core/tools/ITool.d.ts.map +1 -0
- package/dist/core/tools/ITool.js +11 -0
- package/dist/core/tools/ITool.js.map +1 -0
- package/dist/core/tools/IToolOrchestrator.d.ts +131 -0
- package/dist/core/tools/IToolOrchestrator.d.ts.map +1 -0
- package/dist/core/tools/IToolOrchestrator.js +14 -0
- package/dist/core/tools/IToolOrchestrator.js.map +1 -0
- package/dist/core/tools/ToolExecutor.d.ts +143 -0
- package/dist/core/tools/ToolExecutor.d.ts.map +1 -0
- package/dist/core/tools/ToolExecutor.js +364 -0
- package/dist/core/tools/ToolExecutor.js.map +1 -0
- package/dist/core/tools/ToolOrchestrator.d.ts +142 -0
- package/dist/core/tools/ToolOrchestrator.d.ts.map +1 -0
- package/dist/core/tools/ToolOrchestrator.js +373 -0
- package/dist/core/tools/ToolOrchestrator.js.map +1 -0
- package/dist/core/tools/permissions/IToolPermissionManager.d.ts +195 -0
- package/dist/core/tools/permissions/IToolPermissionManager.d.ts.map +1 -0
- package/dist/core/tools/permissions/IToolPermissionManager.js +14 -0
- package/dist/core/tools/permissions/IToolPermissionManager.js.map +1 -0
- package/dist/core/tools/permissions/ToolPermissionManager.d.ts +203 -0
- package/dist/core/tools/permissions/ToolPermissionManager.d.ts.map +1 -0
- package/dist/core/tools/permissions/ToolPermissionManager.js +298 -0
- package/dist/core/tools/permissions/ToolPermissionManager.js.map +1 -0
- package/dist/core/ui/IUIComponent.d.ts +11 -0
- package/dist/core/ui/IUIComponent.d.ts.map +1 -0
- package/dist/core/ui/IUIComponent.js +2 -0
- package/dist/core/ui/IUIComponent.js.map +1 -0
- package/dist/core/usage/UsageLedger.d.ts +81 -0
- package/dist/core/usage/UsageLedger.d.ts.map +1 -0
- package/dist/core/usage/UsageLedger.js +135 -0
- package/dist/core/usage/UsageLedger.js.map +1 -0
- package/dist/core/workflows/IWorkflowEngine.d.ts +42 -0
- package/dist/core/workflows/IWorkflowEngine.d.ts.map +1 -0
- package/dist/core/workflows/IWorkflowEngine.js +2 -0
- package/dist/core/workflows/IWorkflowEngine.js.map +1 -0
- package/dist/core/workflows/WorkflowEngine.d.ts +28 -0
- package/dist/core/workflows/WorkflowEngine.d.ts.map +1 -0
- package/dist/core/workflows/WorkflowEngine.js +309 -0
- package/dist/core/workflows/WorkflowEngine.js.map +1 -0
- package/dist/core/workflows/WorkflowTypes.d.ts +180 -0
- package/dist/core/workflows/WorkflowTypes.d.ts.map +1 -0
- package/dist/core/workflows/WorkflowTypes.js +26 -0
- package/dist/core/workflows/WorkflowTypes.js.map +1 -0
- package/dist/core/workflows/runtime/WorkflowRuntime.d.ts +70 -0
- package/dist/core/workflows/runtime/WorkflowRuntime.d.ts.map +1 -0
- package/dist/core/workflows/runtime/WorkflowRuntime.js +566 -0
- package/dist/core/workflows/runtime/WorkflowRuntime.js.map +1 -0
- package/dist/core/workflows/storage/IWorkflowStore.d.ts +75 -0
- package/dist/core/workflows/storage/IWorkflowStore.d.ts.map +1 -0
- package/dist/core/workflows/storage/IWorkflowStore.js +2 -0
- package/dist/core/workflows/storage/IWorkflowStore.js.map +1 -0
- package/dist/core/workflows/storage/InMemoryWorkflowStore.d.ts +14 -0
- package/dist/core/workflows/storage/InMemoryWorkflowStore.d.ts.map +1 -0
- package/dist/core/workflows/storage/InMemoryWorkflowStore.js +130 -0
- package/dist/core/workflows/storage/InMemoryWorkflowStore.js.map +1 -0
- package/dist/extensions/ExtensionLoader.d.ts +119 -0
- package/dist/extensions/ExtensionLoader.d.ts.map +1 -0
- package/dist/extensions/ExtensionLoader.js +297 -0
- package/dist/extensions/ExtensionLoader.js.map +1 -0
- package/dist/extensions/ExtensionManager.d.ts +49 -0
- package/dist/extensions/ExtensionManager.d.ts.map +1 -0
- package/dist/extensions/ExtensionManager.js +197 -0
- package/dist/extensions/ExtensionManager.js.map +1 -0
- package/dist/extensions/ExtensionRegistry.d.ts +39 -0
- package/dist/extensions/ExtensionRegistry.d.ts.map +1 -0
- package/dist/extensions/ExtensionRegistry.js +103 -0
- package/dist/extensions/ExtensionRegistry.js.map +1 -0
- package/dist/extensions/MultiRegistryLoader.d.ts +61 -0
- package/dist/extensions/MultiRegistryLoader.d.ts.map +1 -0
- package/dist/extensions/MultiRegistryLoader.js +169 -0
- package/dist/extensions/MultiRegistryLoader.js.map +1 -0
- package/dist/extensions/RegistryConfig.d.ts +86 -0
- package/dist/extensions/RegistryConfig.d.ts.map +1 -0
- package/dist/extensions/RegistryConfig.js +99 -0
- package/dist/extensions/RegistryConfig.js.map +1 -0
- package/dist/extensions/events.d.ts +19 -0
- package/dist/extensions/events.d.ts.map +1 -0
- package/dist/extensions/events.js +2 -0
- package/dist/extensions/events.js.map +1 -0
- package/dist/extensions/index.d.ts +9 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +9 -0
- package/dist/extensions/index.js.map +1 -0
- package/dist/extensions/manifest.d.ts +52 -0
- package/dist/extensions/manifest.d.ts.map +1 -0
- package/dist/extensions/manifest.js +2 -0
- package/dist/extensions/manifest.js.map +1 -0
- package/dist/extensions/types.d.ts +294 -0
- package/dist/extensions/types.d.ts.map +1 -0
- package/dist/extensions/types.js +12 -0
- package/dist/extensions/types.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +59 -0
- package/dist/index.js.map +1 -0
- package/dist/logging/ILogger.d.ts +8 -0
- package/dist/logging/ILogger.d.ts.map +1 -0
- package/dist/logging/ILogger.js +2 -0
- package/dist/logging/ILogger.js.map +1 -0
- package/dist/logging/PinoLogger.d.ts +12 -0
- package/dist/logging/PinoLogger.d.ts.map +1 -0
- package/dist/logging/PinoLogger.js +22 -0
- package/dist/logging/PinoLogger.js.map +1 -0
- package/dist/logging/loggerFactory.d.ts +6 -0
- package/dist/logging/loggerFactory.d.ts.map +1 -0
- package/dist/logging/loggerFactory.js +14 -0
- package/dist/logging/loggerFactory.js.map +1 -0
- package/dist/rag/EmbeddingManager.d.ts +81 -0
- package/dist/rag/EmbeddingManager.d.ts.map +1 -0
- package/dist/rag/EmbeddingManager.js +412 -0
- package/dist/rag/EmbeddingManager.js.map +1 -0
- package/dist/rag/IEmbeddingManager.d.ts +277 -0
- package/dist/rag/IEmbeddingManager.d.ts.map +1 -0
- package/dist/rag/IEmbeddingManager.js +19 -0
- package/dist/rag/IEmbeddingManager.js.map +1 -0
- package/dist/rag/IRetrievalAugmentor.d.ts +208 -0
- package/dist/rag/IRetrievalAugmentor.d.ts.map +1 -0
- package/dist/rag/IRetrievalAugmentor.js +21 -0
- package/dist/rag/IRetrievalAugmentor.js.map +1 -0
- package/dist/rag/IVectorStore.d.ts +351 -0
- package/dist/rag/IVectorStore.d.ts.map +1 -0
- package/dist/rag/IVectorStore.js +15 -0
- package/dist/rag/IVectorStore.js.map +1 -0
- package/dist/rag/IVectorStoreManager.d.ts +121 -0
- package/dist/rag/IVectorStoreManager.d.ts.map +1 -0
- package/dist/rag/IVectorStoreManager.js +13 -0
- package/dist/rag/IVectorStoreManager.js.map +1 -0
- package/dist/rag/RetrievalAugmentor.d.ts +99 -0
- package/dist/rag/RetrievalAugmentor.d.ts.map +1 -0
- package/dist/rag/RetrievalAugmentor.js +674 -0
- package/dist/rag/RetrievalAugmentor.js.map +1 -0
- package/dist/rag/VectorStoreManager.d.ts +90 -0
- package/dist/rag/VectorStoreManager.d.ts.map +1 -0
- package/dist/rag/VectorStoreManager.js +283 -0
- package/dist/rag/VectorStoreManager.js.map +1 -0
- package/dist/rag/implementations/index.d.ts +9 -0
- package/dist/rag/implementations/index.d.ts.map +1 -0
- package/dist/rag/implementations/index.js +9 -0
- package/dist/rag/implementations/index.js.map +1 -0
- package/dist/rag/implementations/vector_stores/InMemoryVectorStore.d.ts +132 -0
- package/dist/rag/implementations/vector_stores/InMemoryVectorStore.d.ts.map +1 -0
- package/dist/rag/implementations/vector_stores/InMemoryVectorStore.js +539 -0
- package/dist/rag/implementations/vector_stores/InMemoryVectorStore.js.map +1 -0
- package/dist/rag/implementations/vector_stores/SqlVectorStore.d.ts +265 -0
- package/dist/rag/implementations/vector_stores/SqlVectorStore.d.ts.map +1 -0
- package/dist/rag/implementations/vector_stores/SqlVectorStore.js +755 -0
- package/dist/rag/implementations/vector_stores/SqlVectorStore.js.map +1 -0
- package/dist/rag/implementations/vector_stores/index.d.ts +10 -0
- package/dist/rag/implementations/vector_stores/index.d.ts.map +1 -0
- package/dist/rag/implementations/vector_stores/index.js +12 -0
- package/dist/rag/implementations/vector_stores/index.js.map +1 -0
- package/dist/rag/index.d.ts +95 -0
- package/dist/rag/index.d.ts.map +1 -0
- package/dist/rag/index.js +97 -0
- package/dist/rag/index.js.map +1 -0
- package/dist/services/user_auth/AuthService.d.ts +13 -0
- package/dist/services/user_auth/AuthService.d.ts.map +1 -0
- package/dist/services/user_auth/AuthService.js +24 -0
- package/dist/services/user_auth/AuthService.js.map +1 -0
- package/dist/services/user_auth/SubscriptionService.d.ts +14 -0
- package/dist/services/user_auth/SubscriptionService.d.ts.map +1 -0
- package/dist/services/user_auth/SubscriptionService.js +34 -0
- package/dist/services/user_auth/SubscriptionService.js.map +1 -0
- package/dist/services/user_auth/types.d.ts +30 -0
- package/dist/services/user_auth/types.d.ts.map +1 -0
- package/dist/services/user_auth/types.js +2 -0
- package/dist/services/user_auth/types.js.map +1 -0
- package/dist/stubs/prismaClient.d.ts +35 -0
- package/dist/stubs/prismaClient.d.ts.map +1 -0
- package/dist/stubs/prismaClient.js +47 -0
- package/dist/stubs/prismaClient.js.map +1 -0
- package/dist/types/rateLimitTypes.d.ts +70 -0
- package/dist/types/rateLimitTypes.d.ts.map +1 -0
- package/dist/types/rateLimitTypes.js +55 -0
- package/dist/types/rateLimitTypes.js.map +1 -0
- package/dist/utils/errors.d.ts +80 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +201 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/uuid.d.ts +11 -0
- package/dist/utils/uuid.d.ts.map +1 -0
- package/dist/utils/uuid.js +64 -0
- package/dist/utils/uuid.js.map +1 -0
- package/package.json +84 -0
|
@@ -0,0 +1,755 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview SQL-backed Vector Store Implementation
|
|
3
|
+
*
|
|
4
|
+
* Implements `IVectorStore` using `@framers/sql-storage-adapter` for persistence.
|
|
5
|
+
* This allows vector storage to work across all platforms supported by the storage
|
|
6
|
+
* adapter (SQLite, PostgreSQL, IndexedDB, Capacitor, etc.).
|
|
7
|
+
*
|
|
8
|
+
* **Key Features:**
|
|
9
|
+
* - Cross-platform persistence using sql-storage-adapter
|
|
10
|
+
* - Full-text search support via SQLite FTS5 / PostgreSQL tsvector
|
|
11
|
+
* - Hybrid search (vector similarity + keyword matching)
|
|
12
|
+
* - Automatic schema management
|
|
13
|
+
* - Works with pgvector extension for PostgreSQL (when available)
|
|
14
|
+
*
|
|
15
|
+
* **Architecture:**
|
|
16
|
+
* ```
|
|
17
|
+
* AgentOS RAG System (RetrievalAugmentor)
|
|
18
|
+
* ↓
|
|
19
|
+
* VectorStoreManager
|
|
20
|
+
* ↓
|
|
21
|
+
* SqlVectorStore (this file)
|
|
22
|
+
* ↓
|
|
23
|
+
* @framers/sql-storage-adapter
|
|
24
|
+
* ↓
|
|
25
|
+
* Database (SQLite/PostgreSQL/IndexedDB/etc.)
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* @module @framers/agentos/rag/implementations/vector_stores/SqlVectorStore
|
|
29
|
+
* @see ../../IVectorStore.ts for the interface definition.
|
|
30
|
+
* @see @framers/sql-storage-adapter for storage abstraction.
|
|
31
|
+
*/
|
|
32
|
+
import { resolveStorageAdapter, } from '@framers/sql-storage-adapter';
|
|
33
|
+
import { GMIError, GMIErrorCode } from '../../../utils/errors.js';
|
|
34
|
+
import { uuidv4 } from '../../../utils/uuid.js';
|
|
35
|
+
// ============================================================================
|
|
36
|
+
// SQL Vector Store Implementation
|
|
37
|
+
// ============================================================================
|
|
38
|
+
/**
|
|
39
|
+
* SQL-backed vector store implementation.
|
|
40
|
+
*
|
|
41
|
+
* Uses `@framers/sql-storage-adapter` for cross-platform persistence.
|
|
42
|
+
* Stores embeddings as JSON blobs and computes similarity in application code
|
|
43
|
+
* (with optional native vector extensions for PostgreSQL).
|
|
44
|
+
*
|
|
45
|
+
* @class SqlVectorStore
|
|
46
|
+
* @implements {IVectorStore}
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* const store = new SqlVectorStore();
|
|
51
|
+
*
|
|
52
|
+
* await store.initialize({
|
|
53
|
+
* id: 'sql-vector-store',
|
|
54
|
+
* type: 'sql',
|
|
55
|
+
* storage: {
|
|
56
|
+
* filePath: './vectors.db',
|
|
57
|
+
* priority: ['better-sqlite3', 'sqljs']
|
|
58
|
+
* },
|
|
59
|
+
* enableFullTextSearch: true
|
|
60
|
+
* });
|
|
61
|
+
*
|
|
62
|
+
* // Create a collection
|
|
63
|
+
* await store.createCollection('documents', 1536);
|
|
64
|
+
*
|
|
65
|
+
* // Upsert documents
|
|
66
|
+
* await store.upsert('documents', [{
|
|
67
|
+
* id: 'doc-1',
|
|
68
|
+
* embedding: [...], // 1536-dim vector
|
|
69
|
+
* textContent: 'Example document content',
|
|
70
|
+
* metadata: { author: 'Alice', category: 'tech' }
|
|
71
|
+
* }]);
|
|
72
|
+
*
|
|
73
|
+
* // Query by similarity
|
|
74
|
+
* const results = await store.query('documents', queryEmbedding, { topK: 5 });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
export class SqlVectorStore {
|
|
78
|
+
/**
|
|
79
|
+
* Constructs a SqlVectorStore instance.
|
|
80
|
+
* The store is not operational until `initialize()` is called.
|
|
81
|
+
*/
|
|
82
|
+
constructor() {
|
|
83
|
+
this.ownsAdapter = false; // Whether we created the adapter
|
|
84
|
+
this.isInitialized = false;
|
|
85
|
+
this.tablePrefix = 'agentos_rag_';
|
|
86
|
+
this.providerId = `sql-vector-store-${uuidv4()}`;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Initializes the vector store with the provided configuration.
|
|
90
|
+
*
|
|
91
|
+
* Creates necessary tables and indexes if they don't exist.
|
|
92
|
+
*
|
|
93
|
+
* @param {VectorStoreProviderConfig} config - Configuration object
|
|
94
|
+
* @throws {GMIError} If configuration is invalid or initialization fails
|
|
95
|
+
*/
|
|
96
|
+
async initialize(config) {
|
|
97
|
+
if (this.isInitialized) {
|
|
98
|
+
console.warn(`SqlVectorStore (ID: ${this.providerId}) already initialized. Re-initializing.`);
|
|
99
|
+
await this.shutdown();
|
|
100
|
+
}
|
|
101
|
+
if (config.type !== 'sql') {
|
|
102
|
+
throw new GMIError(`Invalid configuration type for SqlVectorStore: ${config.type}. Expected 'sql'.`, GMIErrorCode.CONFIG_ERROR, { providedType: config.type });
|
|
103
|
+
}
|
|
104
|
+
this.config = config;
|
|
105
|
+
this.tablePrefix = this.config.tablePrefix ?? 'agentos_rag_';
|
|
106
|
+
// Initialize storage adapter
|
|
107
|
+
if (this.config.adapter) {
|
|
108
|
+
this.adapter = this.config.adapter;
|
|
109
|
+
this.ownsAdapter = false;
|
|
110
|
+
}
|
|
111
|
+
else if (this.config.storage) {
|
|
112
|
+
this.adapter = await resolveStorageAdapter(this.config.storage);
|
|
113
|
+
this.ownsAdapter = true;
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// Default to sql.js (in-memory when no file path provided)
|
|
117
|
+
this.adapter = await resolveStorageAdapter({ priority: ['sqljs'] });
|
|
118
|
+
this.ownsAdapter = true;
|
|
119
|
+
console.warn(`SqlVectorStore (ID: ${this.providerId}): No storage config provided, using sql.js (in-memory).`);
|
|
120
|
+
}
|
|
121
|
+
// Create schema
|
|
122
|
+
await this.createSchema();
|
|
123
|
+
this.isInitialized = true;
|
|
124
|
+
console.log(`SqlVectorStore (ID: ${this.providerId}, Config ID: ${this.config.id}) initialized successfully.`);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Creates the database schema for vector storage.
|
|
128
|
+
* @private
|
|
129
|
+
*/
|
|
130
|
+
async createSchema() {
|
|
131
|
+
// Collections metadata table
|
|
132
|
+
await this.adapter.exec(`
|
|
133
|
+
CREATE TABLE IF NOT EXISTS ${this.tablePrefix}collections (
|
|
134
|
+
name TEXT PRIMARY KEY,
|
|
135
|
+
dimension INTEGER NOT NULL,
|
|
136
|
+
similarity_metric TEXT NOT NULL DEFAULT 'cosine',
|
|
137
|
+
document_count INTEGER NOT NULL DEFAULT 0,
|
|
138
|
+
created_at INTEGER NOT NULL,
|
|
139
|
+
updated_at INTEGER NOT NULL
|
|
140
|
+
);
|
|
141
|
+
`);
|
|
142
|
+
// Documents table - stores vectors as JSON blobs
|
|
143
|
+
await this.adapter.exec(`
|
|
144
|
+
CREATE TABLE IF NOT EXISTS ${this.tablePrefix}documents (
|
|
145
|
+
id TEXT NOT NULL,
|
|
146
|
+
collection_name TEXT NOT NULL,
|
|
147
|
+
embedding_blob TEXT NOT NULL,
|
|
148
|
+
text_content TEXT,
|
|
149
|
+
metadata_json TEXT,
|
|
150
|
+
created_at INTEGER NOT NULL,
|
|
151
|
+
updated_at INTEGER NOT NULL,
|
|
152
|
+
PRIMARY KEY (collection_name, id),
|
|
153
|
+
FOREIGN KEY (collection_name) REFERENCES ${this.tablePrefix}collections(name) ON DELETE CASCADE
|
|
154
|
+
);
|
|
155
|
+
|
|
156
|
+
CREATE INDEX IF NOT EXISTS idx_${this.tablePrefix}docs_collection
|
|
157
|
+
ON ${this.tablePrefix}documents(collection_name);
|
|
158
|
+
|
|
159
|
+
CREATE INDEX IF NOT EXISTS idx_${this.tablePrefix}docs_updated
|
|
160
|
+
ON ${this.tablePrefix}documents(updated_at);
|
|
161
|
+
`);
|
|
162
|
+
// Full-text search virtual table (SQLite FTS5)
|
|
163
|
+
if (this.config.enableFullTextSearch !== false) {
|
|
164
|
+
try {
|
|
165
|
+
await this.adapter.exec(`
|
|
166
|
+
CREATE VIRTUAL TABLE IF NOT EXISTS ${this.tablePrefix}documents_fts
|
|
167
|
+
USING fts5(
|
|
168
|
+
id,
|
|
169
|
+
collection_name,
|
|
170
|
+
text_content,
|
|
171
|
+
content='${this.tablePrefix}documents',
|
|
172
|
+
content_rowid='rowid'
|
|
173
|
+
);
|
|
174
|
+
`);
|
|
175
|
+
console.log(`SqlVectorStore (ID: ${this.providerId}): FTS5 index created.`);
|
|
176
|
+
}
|
|
177
|
+
catch (error) {
|
|
178
|
+
// FTS5 might not be available (e.g., in some SQL.js builds)
|
|
179
|
+
console.warn(`SqlVectorStore (ID: ${this.providerId}): FTS5 not available: ${error.message}`);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Ensures the store is initialized before operations.
|
|
185
|
+
* @private
|
|
186
|
+
*/
|
|
187
|
+
ensureInitialized() {
|
|
188
|
+
if (!this.isInitialized) {
|
|
189
|
+
throw new GMIError(`SqlVectorStore (ID: ${this.providerId}) is not initialized. Call initialize() first.`, GMIErrorCode.NOT_INITIALIZED);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Creates a new collection for storing vectors.
|
|
194
|
+
*
|
|
195
|
+
* @param {string} collectionName - Unique name for the collection
|
|
196
|
+
* @param {number} dimension - Vector embedding dimension
|
|
197
|
+
* @param {CreateCollectionOptions} [options] - Creation options
|
|
198
|
+
*/
|
|
199
|
+
async createCollection(collectionName, dimension, options) {
|
|
200
|
+
this.ensureInitialized();
|
|
201
|
+
if (dimension <= 0) {
|
|
202
|
+
throw new GMIError(`Invalid dimension for collection '${collectionName}': ${dimension}. Must be positive.`, GMIErrorCode.VALIDATION_ERROR, { dimension });
|
|
203
|
+
}
|
|
204
|
+
const exists = await this.collectionExists(collectionName);
|
|
205
|
+
if (exists) {
|
|
206
|
+
if (options?.overwriteIfExists) {
|
|
207
|
+
await this.deleteCollection(collectionName);
|
|
208
|
+
}
|
|
209
|
+
else {
|
|
210
|
+
throw new GMIError(`Collection '${collectionName}' already exists.`, GMIErrorCode.ALREADY_EXISTS, { collectionName });
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const now = Date.now();
|
|
214
|
+
const metric = options?.similarityMetric ?? this.config.similarityMetric ?? 'cosine';
|
|
215
|
+
await this.adapter.run(`INSERT INTO ${this.tablePrefix}collections
|
|
216
|
+
(name, dimension, similarity_metric, document_count, created_at, updated_at)
|
|
217
|
+
VALUES (?, ?, ?, 0, ?, ?)`, [collectionName, dimension, metric, now, now]);
|
|
218
|
+
console.log(`SqlVectorStore (ID: ${this.providerId}): Collection '${collectionName}' created (dim=${dimension}, metric=${metric}).`);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Checks if a collection exists.
|
|
222
|
+
*
|
|
223
|
+
* @param {string} collectionName - Collection name to check
|
|
224
|
+
* @returns {Promise<boolean>} True if collection exists
|
|
225
|
+
*/
|
|
226
|
+
async collectionExists(collectionName) {
|
|
227
|
+
this.ensureInitialized();
|
|
228
|
+
const row = await this.adapter.get(`SELECT COUNT(*) as count FROM ${this.tablePrefix}collections WHERE name = ?`, [collectionName]);
|
|
229
|
+
return (row?.count ?? 0) > 0;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Deletes a collection and all its documents.
|
|
233
|
+
*
|
|
234
|
+
* @param {string} collectionName - Collection to delete
|
|
235
|
+
*/
|
|
236
|
+
async deleteCollection(collectionName) {
|
|
237
|
+
this.ensureInitialized();
|
|
238
|
+
// Delete documents first (due to foreign key)
|
|
239
|
+
await this.adapter.run(`DELETE FROM ${this.tablePrefix}documents WHERE collection_name = ?`, [collectionName]);
|
|
240
|
+
// Delete collection metadata
|
|
241
|
+
await this.adapter.run(`DELETE FROM ${this.tablePrefix}collections WHERE name = ?`, [collectionName]);
|
|
242
|
+
console.log(`SqlVectorStore (ID: ${this.providerId}): Collection '${collectionName}' deleted.`);
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Gets collection metadata.
|
|
246
|
+
* @private
|
|
247
|
+
*/
|
|
248
|
+
async getCollectionMetadata(collectionName) {
|
|
249
|
+
const row = await this.adapter.get(`SELECT * FROM ${this.tablePrefix}collections WHERE name = ?`, [collectionName]);
|
|
250
|
+
if (!row) {
|
|
251
|
+
throw new GMIError(`Collection '${collectionName}' not found.`, GMIErrorCode.NOT_FOUND, { collectionName });
|
|
252
|
+
}
|
|
253
|
+
return {
|
|
254
|
+
name: row.name,
|
|
255
|
+
dimension: row.dimension,
|
|
256
|
+
similarityMetric: row.similarity_metric,
|
|
257
|
+
documentCount: row.document_count,
|
|
258
|
+
createdAt: row.created_at,
|
|
259
|
+
updatedAt: row.updated_at,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Upserts documents into a collection.
|
|
264
|
+
*
|
|
265
|
+
* @param {string} collectionName - Target collection
|
|
266
|
+
* @param {VectorDocument[]} documents - Documents to upsert
|
|
267
|
+
* @param {UpsertOptions} [options] - Upsert options
|
|
268
|
+
* @returns {Promise<UpsertResult>} Result of the upsert operation
|
|
269
|
+
*/
|
|
270
|
+
async upsert(collectionName, documents, options) {
|
|
271
|
+
this.ensureInitialized();
|
|
272
|
+
const collection = await this.getCollectionMetadata(collectionName);
|
|
273
|
+
const upsertedIds = [];
|
|
274
|
+
const errors = [];
|
|
275
|
+
const now = Date.now();
|
|
276
|
+
for (const doc of documents) {
|
|
277
|
+
// Validate dimension
|
|
278
|
+
if (doc.embedding.length !== collection.dimension) {
|
|
279
|
+
errors.push({
|
|
280
|
+
id: doc.id,
|
|
281
|
+
message: `Embedding dimension ${doc.embedding.length} does not match collection dimension ${collection.dimension}.`,
|
|
282
|
+
details: { expected: collection.dimension, got: doc.embedding.length }
|
|
283
|
+
});
|
|
284
|
+
continue;
|
|
285
|
+
}
|
|
286
|
+
try {
|
|
287
|
+
// Check if document exists
|
|
288
|
+
const existing = await this.adapter.get(`SELECT id FROM ${this.tablePrefix}documents WHERE collection_name = ? AND id = ?`, [collectionName, doc.id]);
|
|
289
|
+
const embeddingBlob = JSON.stringify(doc.embedding);
|
|
290
|
+
const metadataJson = doc.metadata ? JSON.stringify(doc.metadata) : null;
|
|
291
|
+
if (existing && options?.overwrite === false) {
|
|
292
|
+
errors.push({
|
|
293
|
+
id: doc.id,
|
|
294
|
+
message: `Document '${doc.id}' already exists and overwrite is disabled.`,
|
|
295
|
+
details: { reason: 'NO_OVERWRITE' }
|
|
296
|
+
});
|
|
297
|
+
continue;
|
|
298
|
+
}
|
|
299
|
+
if (existing) {
|
|
300
|
+
// Update existing document
|
|
301
|
+
await this.adapter.run(`UPDATE ${this.tablePrefix}documents
|
|
302
|
+
SET embedding_blob = ?, text_content = ?, metadata_json = ?, updated_at = ?
|
|
303
|
+
WHERE collection_name = ? AND id = ?`, [embeddingBlob, doc.textContent ?? null, metadataJson, now, collectionName, doc.id]);
|
|
304
|
+
}
|
|
305
|
+
else {
|
|
306
|
+
// Insert new document
|
|
307
|
+
await this.adapter.run(`INSERT INTO ${this.tablePrefix}documents
|
|
308
|
+
(id, collection_name, embedding_blob, text_content, metadata_json, created_at, updated_at)
|
|
309
|
+
VALUES (?, ?, ?, ?, ?, ?, ?)`, [doc.id, collectionName, embeddingBlob, doc.textContent ?? null, metadataJson, now, now]);
|
|
310
|
+
}
|
|
311
|
+
upsertedIds.push(doc.id);
|
|
312
|
+
}
|
|
313
|
+
catch (error) {
|
|
314
|
+
errors.push({
|
|
315
|
+
id: doc.id,
|
|
316
|
+
message: `Failed to upsert document: ${error.message}`,
|
|
317
|
+
details: error
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
// Update collection document count
|
|
322
|
+
const countResult = await this.adapter.get(`SELECT COUNT(*) as count FROM ${this.tablePrefix}documents WHERE collection_name = ?`, [collectionName]);
|
|
323
|
+
await this.adapter.run(`UPDATE ${this.tablePrefix}collections SET document_count = ?, updated_at = ? WHERE name = ?`, [countResult?.count ?? 0, now, collectionName]);
|
|
324
|
+
return {
|
|
325
|
+
upsertedCount: upsertedIds.length,
|
|
326
|
+
upsertedIds,
|
|
327
|
+
failedCount: errors.length,
|
|
328
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* Queries a collection for similar documents.
|
|
333
|
+
*
|
|
334
|
+
* @param {string} collectionName - Collection to query
|
|
335
|
+
* @param {number[]} queryEmbedding - Query vector
|
|
336
|
+
* @param {QueryOptions} [options] - Query options
|
|
337
|
+
* @returns {Promise<QueryResult>} Query results sorted by similarity
|
|
338
|
+
*/
|
|
339
|
+
async query(collectionName, queryEmbedding, options) {
|
|
340
|
+
this.ensureInitialized();
|
|
341
|
+
const collection = await this.getCollectionMetadata(collectionName);
|
|
342
|
+
const topK = options?.topK ?? 10;
|
|
343
|
+
// Validate query embedding dimension
|
|
344
|
+
if (queryEmbedding.length !== collection.dimension) {
|
|
345
|
+
throw new GMIError(`Query embedding dimension ${queryEmbedding.length} does not match collection dimension ${collection.dimension}.`, GMIErrorCode.VALIDATION_ERROR, { expected: collection.dimension, got: queryEmbedding.length });
|
|
346
|
+
}
|
|
347
|
+
// Build query with optional metadata filter
|
|
348
|
+
const query = `SELECT * FROM ${this.tablePrefix}documents WHERE collection_name = ?`;
|
|
349
|
+
const params = [collectionName];
|
|
350
|
+
// Note: For more advanced filtering, we'd parse the MetadataFilter and generate SQL
|
|
351
|
+
// For now, we filter in application code for flexibility
|
|
352
|
+
const rows = await this.adapter.all(query, params);
|
|
353
|
+
// Compute similarities and filter
|
|
354
|
+
const candidates = [];
|
|
355
|
+
for (const row of rows) {
|
|
356
|
+
const embedding = JSON.parse(row.embedding_blob);
|
|
357
|
+
const metadata = row.metadata_json ? JSON.parse(row.metadata_json) : undefined;
|
|
358
|
+
// Apply metadata filter in application code
|
|
359
|
+
if (options?.filter && !this.matchesFilter(metadata, options.filter)) {
|
|
360
|
+
continue;
|
|
361
|
+
}
|
|
362
|
+
// Compute similarity
|
|
363
|
+
let similarityScore;
|
|
364
|
+
switch (collection.similarityMetric) {
|
|
365
|
+
case 'euclidean':
|
|
366
|
+
similarityScore = -this.euclideanDistance(queryEmbedding, embedding); // Negate for "higher is better"
|
|
367
|
+
break;
|
|
368
|
+
case 'dotproduct':
|
|
369
|
+
similarityScore = this.dotProduct(queryEmbedding, embedding);
|
|
370
|
+
break;
|
|
371
|
+
case 'cosine':
|
|
372
|
+
default:
|
|
373
|
+
similarityScore = this.cosineSimilarity(queryEmbedding, embedding);
|
|
374
|
+
break;
|
|
375
|
+
}
|
|
376
|
+
// Apply minimum similarity threshold
|
|
377
|
+
if (options?.minSimilarityScore !== undefined && similarityScore < options.minSimilarityScore) {
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
// Build result document
|
|
381
|
+
const retrievedDoc = {
|
|
382
|
+
id: row.id,
|
|
383
|
+
embedding: options?.includeEmbedding ? embedding : [],
|
|
384
|
+
similarityScore,
|
|
385
|
+
};
|
|
386
|
+
if (options?.includeMetadata !== false && metadata) {
|
|
387
|
+
retrievedDoc.metadata = metadata;
|
|
388
|
+
}
|
|
389
|
+
if (options?.includeTextContent && row.text_content) {
|
|
390
|
+
retrievedDoc.textContent = row.text_content;
|
|
391
|
+
}
|
|
392
|
+
candidates.push(retrievedDoc);
|
|
393
|
+
}
|
|
394
|
+
// Sort by similarity (descending) and take topK
|
|
395
|
+
candidates.sort((a, b) => b.similarityScore - a.similarityScore);
|
|
396
|
+
const results = candidates.slice(0, topK);
|
|
397
|
+
return {
|
|
398
|
+
documents: results,
|
|
399
|
+
queryId: `sql-query-${uuidv4()}`,
|
|
400
|
+
stats: {
|
|
401
|
+
totalCandidates: rows.length,
|
|
402
|
+
filteredCandidates: candidates.length,
|
|
403
|
+
returnedCount: results.length,
|
|
404
|
+
},
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
/**
|
|
408
|
+
* Performs hybrid search combining vector similarity with keyword matching.
|
|
409
|
+
*
|
|
410
|
+
* @param {string} collectionName - Collection to search
|
|
411
|
+
* @param {number[]} queryEmbedding - Query vector for semantic search
|
|
412
|
+
* @param {string} queryText - Text query for keyword search
|
|
413
|
+
* @param {QueryOptions & { alpha?: number }} [options] - Search options
|
|
414
|
+
* @returns {Promise<QueryResult>} Combined search results
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* const results = await store.hybridSearch(
|
|
419
|
+
* 'documents',
|
|
420
|
+
* queryEmbedding,
|
|
421
|
+
* 'machine learning tutorial',
|
|
422
|
+
* { topK: 10, alpha: 0.7 } // 70% vector, 30% keyword
|
|
423
|
+
* );
|
|
424
|
+
* ```
|
|
425
|
+
*/
|
|
426
|
+
async hybridSearch(collectionName, queryEmbedding, queryText, options) {
|
|
427
|
+
this.ensureInitialized();
|
|
428
|
+
const alpha = options?.alpha ?? 0.7; // Default: 70% vector similarity
|
|
429
|
+
const topK = options?.topK ?? 10;
|
|
430
|
+
// Get vector search results
|
|
431
|
+
const vectorResults = await this.query(collectionName, queryEmbedding, {
|
|
432
|
+
...options,
|
|
433
|
+
topK: topK * 3, // Get more candidates for merging
|
|
434
|
+
includeTextContent: true,
|
|
435
|
+
});
|
|
436
|
+
// Normalize vector scores to [0, 1]
|
|
437
|
+
const maxVectorScore = Math.max(...vectorResults.documents.map(d => d.similarityScore), 0.001);
|
|
438
|
+
const vectorScoreMap = new Map();
|
|
439
|
+
for (const doc of vectorResults.documents) {
|
|
440
|
+
vectorScoreMap.set(doc.id, doc.similarityScore / maxVectorScore);
|
|
441
|
+
}
|
|
442
|
+
// Compute keyword scores using simple term matching
|
|
443
|
+
const queryTerms = queryText.toLowerCase().split(/\s+/).filter(t => t.length > 2);
|
|
444
|
+
const keywordScoreMap = new Map();
|
|
445
|
+
for (const doc of vectorResults.documents) {
|
|
446
|
+
if (!doc.textContent)
|
|
447
|
+
continue;
|
|
448
|
+
const content = doc.textContent.toLowerCase();
|
|
449
|
+
let matchCount = 0;
|
|
450
|
+
for (const term of queryTerms) {
|
|
451
|
+
if (content.includes(term)) {
|
|
452
|
+
matchCount++;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const keywordScore = queryTerms.length > 0 ? matchCount / queryTerms.length : 0;
|
|
456
|
+
keywordScoreMap.set(doc.id, keywordScore);
|
|
457
|
+
}
|
|
458
|
+
// Combine scores using reciprocal rank fusion or weighted average
|
|
459
|
+
const combinedResults = [];
|
|
460
|
+
for (const doc of vectorResults.documents) {
|
|
461
|
+
const vectorScore = vectorScoreMap.get(doc.id) ?? 0;
|
|
462
|
+
const keywordScore = keywordScoreMap.get(doc.id) ?? 0;
|
|
463
|
+
const combinedScore = alpha * vectorScore + (1 - alpha) * keywordScore;
|
|
464
|
+
combinedResults.push({
|
|
465
|
+
...doc,
|
|
466
|
+
similarityScore: combinedScore,
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
// Sort by combined score and return top K
|
|
470
|
+
combinedResults.sort((a, b) => b.similarityScore - a.similarityScore);
|
|
471
|
+
return {
|
|
472
|
+
documents: combinedResults.slice(0, topK),
|
|
473
|
+
queryId: `sql-hybrid-${uuidv4()}`,
|
|
474
|
+
stats: {
|
|
475
|
+
vectorWeight: alpha,
|
|
476
|
+
keywordWeight: 1 - alpha,
|
|
477
|
+
queryTerms: queryTerms.length,
|
|
478
|
+
},
|
|
479
|
+
};
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Deletes documents from a collection.
|
|
483
|
+
*
|
|
484
|
+
* @param {string} collectionName - Collection to delete from
|
|
485
|
+
* @param {string[]} [ids] - Specific document IDs to delete
|
|
486
|
+
* @param {DeleteOptions} [options] - Delete options (filter, deleteAll)
|
|
487
|
+
* @returns {Promise<DeleteResult>} Deletion result
|
|
488
|
+
*/
|
|
489
|
+
async delete(collectionName, ids, options) {
|
|
490
|
+
this.ensureInitialized();
|
|
491
|
+
let deletedCount = 0;
|
|
492
|
+
const errors = [];
|
|
493
|
+
if (options?.deleteAll && !ids && !options.filter) {
|
|
494
|
+
// Delete all documents in collection
|
|
495
|
+
const result = await this.adapter.run(`DELETE FROM ${this.tablePrefix}documents WHERE collection_name = ?`, [collectionName]);
|
|
496
|
+
deletedCount = result.changes;
|
|
497
|
+
console.warn(`SqlVectorStore (ID: ${this.providerId}): All ${deletedCount} documents deleted from '${collectionName}'.`);
|
|
498
|
+
}
|
|
499
|
+
else if (ids && ids.length > 0) {
|
|
500
|
+
// Delete specific IDs
|
|
501
|
+
const placeholders = ids.map(() => '?').join(',');
|
|
502
|
+
const result = await this.adapter.run(`DELETE FROM ${this.tablePrefix}documents WHERE collection_name = ? AND id IN (${placeholders})`, [collectionName, ...ids]);
|
|
503
|
+
deletedCount = result.changes;
|
|
504
|
+
}
|
|
505
|
+
else if (options?.filter) {
|
|
506
|
+
// Delete by filter (fetch matching docs first, then delete)
|
|
507
|
+
const rows = await this.adapter.all(`SELECT id, metadata_json FROM ${this.tablePrefix}documents WHERE collection_name = ?`, [collectionName]);
|
|
508
|
+
const idsToDelete = [];
|
|
509
|
+
for (const row of rows) {
|
|
510
|
+
const metadata = row.metadata_json ? JSON.parse(row.metadata_json) : undefined;
|
|
511
|
+
if (this.matchesFilter(metadata, options.filter)) {
|
|
512
|
+
idsToDelete.push(row.id);
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
if (idsToDelete.length > 0) {
|
|
516
|
+
const placeholders = idsToDelete.map(() => '?').join(',');
|
|
517
|
+
const result = await this.adapter.run(`DELETE FROM ${this.tablePrefix}documents WHERE collection_name = ? AND id IN (${placeholders})`, [collectionName, ...idsToDelete]);
|
|
518
|
+
deletedCount = result.changes;
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
// Update collection document count
|
|
522
|
+
const now = Date.now();
|
|
523
|
+
const countResult = await this.adapter.get(`SELECT COUNT(*) as count FROM ${this.tablePrefix}documents WHERE collection_name = ?`, [collectionName]);
|
|
524
|
+
await this.adapter.run(`UPDATE ${this.tablePrefix}collections SET document_count = ?, updated_at = ? WHERE name = ?`, [countResult?.count ?? 0, now, collectionName]);
|
|
525
|
+
return {
|
|
526
|
+
deletedCount,
|
|
527
|
+
failedCount: errors.length > 0 ? errors.length : undefined,
|
|
528
|
+
errors: errors.length > 0 ? errors : undefined,
|
|
529
|
+
};
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Checks the health of the vector store.
|
|
533
|
+
*
|
|
534
|
+
* @returns {Promise<{ isHealthy: boolean; details?: any }>} Health status
|
|
535
|
+
*/
|
|
536
|
+
async checkHealth() {
|
|
537
|
+
try {
|
|
538
|
+
this.ensureInitialized();
|
|
539
|
+
// Simple health check query
|
|
540
|
+
const collections = await this.adapter.all(`SELECT name, document_count FROM ${this.tablePrefix}collections`);
|
|
541
|
+
const totalDocuments = collections.reduce((sum, c) => sum + c.document_count, 0);
|
|
542
|
+
return {
|
|
543
|
+
isHealthy: true,
|
|
544
|
+
details: {
|
|
545
|
+
providerId: this.providerId,
|
|
546
|
+
configId: this.config.id,
|
|
547
|
+
type: 'sql',
|
|
548
|
+
collectionCount: collections.length,
|
|
549
|
+
totalDocuments,
|
|
550
|
+
collections: collections.map(c => ({ name: c.name, documentCount: c.document_count })),
|
|
551
|
+
},
|
|
552
|
+
};
|
|
553
|
+
}
|
|
554
|
+
catch (error) {
|
|
555
|
+
return {
|
|
556
|
+
isHealthy: false,
|
|
557
|
+
details: {
|
|
558
|
+
providerId: this.providerId,
|
|
559
|
+
error: error.message,
|
|
560
|
+
},
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
565
|
+
* Gracefully shuts down the vector store.
|
|
566
|
+
*/
|
|
567
|
+
async shutdown() {
|
|
568
|
+
if (!this.isInitialized) {
|
|
569
|
+
return;
|
|
570
|
+
}
|
|
571
|
+
if (this.ownsAdapter && this.adapter) {
|
|
572
|
+
await this.adapter.close();
|
|
573
|
+
}
|
|
574
|
+
this.isInitialized = false;
|
|
575
|
+
console.log(`SqlVectorStore (ID: ${this.providerId}) shut down.`);
|
|
576
|
+
}
|
|
577
|
+
/**
|
|
578
|
+
* Gets statistics for a collection or the entire store.
|
|
579
|
+
*
|
|
580
|
+
* @param {string} [collectionName] - Specific collection, or all if omitted
|
|
581
|
+
* @returns {Promise<Record<string, any>>} Statistics
|
|
582
|
+
*/
|
|
583
|
+
async getStats(collectionName) {
|
|
584
|
+
this.ensureInitialized();
|
|
585
|
+
if (collectionName) {
|
|
586
|
+
const collection = await this.getCollectionMetadata(collectionName);
|
|
587
|
+
return {
|
|
588
|
+
collectionName: collection.name,
|
|
589
|
+
dimension: collection.dimension,
|
|
590
|
+
similarityMetric: collection.similarityMetric,
|
|
591
|
+
documentCount: collection.documentCount,
|
|
592
|
+
createdAt: collection.createdAt,
|
|
593
|
+
updatedAt: collection.updatedAt,
|
|
594
|
+
};
|
|
595
|
+
}
|
|
596
|
+
const collections = await this.adapter.all(`SELECT * FROM ${this.tablePrefix}collections`);
|
|
597
|
+
return {
|
|
598
|
+
providerId: this.providerId,
|
|
599
|
+
configId: this.config.id,
|
|
600
|
+
type: 'sql',
|
|
601
|
+
collectionCount: collections.length,
|
|
602
|
+
totalDocuments: collections.reduce((sum, c) => sum + c.document_count, 0),
|
|
603
|
+
collections: collections.map((c) => ({
|
|
604
|
+
name: c.name,
|
|
605
|
+
dimension: c.dimension,
|
|
606
|
+
documentCount: c.document_count,
|
|
607
|
+
})),
|
|
608
|
+
};
|
|
609
|
+
}
|
|
610
|
+
// ============================================================================
|
|
611
|
+
// Private Helper Methods
|
|
612
|
+
// ============================================================================
|
|
613
|
+
/**
|
|
614
|
+
* Computes cosine similarity between two vectors.
|
|
615
|
+
* @private
|
|
616
|
+
*/
|
|
617
|
+
cosineSimilarity(vecA, vecB) {
|
|
618
|
+
let dotProduct = 0;
|
|
619
|
+
let normA = 0;
|
|
620
|
+
let normB = 0;
|
|
621
|
+
for (let i = 0; i < vecA.length; i++) {
|
|
622
|
+
dotProduct += vecA[i] * vecB[i];
|
|
623
|
+
normA += vecA[i] * vecA[i];
|
|
624
|
+
normB += vecB[i] * vecB[i];
|
|
625
|
+
}
|
|
626
|
+
const magnitudeA = Math.sqrt(normA);
|
|
627
|
+
const magnitudeB = Math.sqrt(normB);
|
|
628
|
+
if (magnitudeA === 0 || magnitudeB === 0) {
|
|
629
|
+
return 0;
|
|
630
|
+
}
|
|
631
|
+
return dotProduct / (magnitudeA * magnitudeB);
|
|
632
|
+
}
|
|
633
|
+
/**
|
|
634
|
+
* Computes Euclidean distance between two vectors.
|
|
635
|
+
* @private
|
|
636
|
+
*/
|
|
637
|
+
euclideanDistance(vecA, vecB) {
|
|
638
|
+
let sum = 0;
|
|
639
|
+
for (let i = 0; i < vecA.length; i++) {
|
|
640
|
+
const diff = vecA[i] - vecB[i];
|
|
641
|
+
sum += diff * diff;
|
|
642
|
+
}
|
|
643
|
+
return Math.sqrt(sum);
|
|
644
|
+
}
|
|
645
|
+
/**
|
|
646
|
+
* Computes dot product between two vectors.
|
|
647
|
+
* @private
|
|
648
|
+
*/
|
|
649
|
+
dotProduct(vecA, vecB) {
|
|
650
|
+
let sum = 0;
|
|
651
|
+
for (let i = 0; i < vecA.length; i++) {
|
|
652
|
+
sum += vecA[i] * vecB[i];
|
|
653
|
+
}
|
|
654
|
+
return sum;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Checks if metadata matches a filter.
|
|
658
|
+
* @private
|
|
659
|
+
*/
|
|
660
|
+
matchesFilter(metadata, filter) {
|
|
661
|
+
if (!metadata) {
|
|
662
|
+
// Check if filter only has $exists: false conditions
|
|
663
|
+
for (const key in filter) {
|
|
664
|
+
const condition = filter[key];
|
|
665
|
+
if (typeof condition === 'object' && condition !== null && condition.$exists === false) {
|
|
666
|
+
continue;
|
|
667
|
+
}
|
|
668
|
+
return false;
|
|
669
|
+
}
|
|
670
|
+
return true;
|
|
671
|
+
}
|
|
672
|
+
for (const key in filter) {
|
|
673
|
+
const docValue = metadata[key];
|
|
674
|
+
const filterValue = filter[key];
|
|
675
|
+
if (typeof filterValue === 'object' && filterValue !== null) {
|
|
676
|
+
if (!this.evaluateCondition(docValue, filterValue)) {
|
|
677
|
+
return false;
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
else {
|
|
681
|
+
// Direct equality check
|
|
682
|
+
if (Array.isArray(docValue)) {
|
|
683
|
+
if (!docValue.includes(filterValue)) {
|
|
684
|
+
return false;
|
|
685
|
+
}
|
|
686
|
+
}
|
|
687
|
+
else if (docValue !== filterValue) {
|
|
688
|
+
return false;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
return true;
|
|
693
|
+
}
|
|
694
|
+
/**
|
|
695
|
+
* Evaluates a single filter condition.
|
|
696
|
+
* @private
|
|
697
|
+
*/
|
|
698
|
+
evaluateCondition(docValue, condition) {
|
|
699
|
+
if (condition.$exists !== undefined) {
|
|
700
|
+
return condition.$exists === (docValue !== undefined);
|
|
701
|
+
}
|
|
702
|
+
if (docValue === undefined)
|
|
703
|
+
return false;
|
|
704
|
+
if (condition.$eq !== undefined && docValue !== condition.$eq)
|
|
705
|
+
return false;
|
|
706
|
+
if (condition.$ne !== undefined && docValue === condition.$ne)
|
|
707
|
+
return false;
|
|
708
|
+
if (typeof docValue === 'number') {
|
|
709
|
+
if (condition.$gt !== undefined && !(docValue > condition.$gt))
|
|
710
|
+
return false;
|
|
711
|
+
if (condition.$gte !== undefined && !(docValue >= condition.$gte))
|
|
712
|
+
return false;
|
|
713
|
+
if (condition.$lt !== undefined && !(docValue < condition.$lt))
|
|
714
|
+
return false;
|
|
715
|
+
if (condition.$lte !== undefined && !(docValue <= condition.$lte))
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
if (condition.$in !== undefined) {
|
|
719
|
+
if (Array.isArray(docValue)) {
|
|
720
|
+
if (!docValue.some(val => condition.$in.includes(val)))
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
else {
|
|
724
|
+
if (!condition.$in.includes(docValue))
|
|
725
|
+
return false;
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
if (condition.$nin !== undefined) {
|
|
729
|
+
if (Array.isArray(docValue)) {
|
|
730
|
+
if (docValue.some(val => condition.$nin.includes(val)))
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
else {
|
|
734
|
+
if (condition.$nin.includes(docValue))
|
|
735
|
+
return false;
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
if (Array.isArray(docValue)) {
|
|
739
|
+
if (condition.$contains !== undefined && !docValue.includes(condition.$contains))
|
|
740
|
+
return false;
|
|
741
|
+
if (condition.$all !== undefined && !condition.$all.every(item => docValue.includes(item)))
|
|
742
|
+
return false;
|
|
743
|
+
}
|
|
744
|
+
else if (typeof docValue === 'string' && condition.$contains !== undefined) {
|
|
745
|
+
if (!docValue.includes(String(condition.$contains)))
|
|
746
|
+
return false;
|
|
747
|
+
}
|
|
748
|
+
if (condition.$textSearch !== undefined && typeof docValue === 'string') {
|
|
749
|
+
if (!docValue.toLowerCase().includes(condition.$textSearch.toLowerCase()))
|
|
750
|
+
return false;
|
|
751
|
+
}
|
|
752
|
+
return true;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
//# sourceMappingURL=SqlVectorStore.js.map
|