htm 0.0.32 → 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.
- checksums.yaml +4 -4
- data/.architecture/decisions/adrs/005-rag-based-retrieval-with-hybrid-search.md +4 -0
- data/.architecture/decisions/adrs/017-bitemporal-event-time.md +78 -0
- data/.architecture/decisions/adrs/018-memory-timelines-and-node-links.md +64 -0
- data/.architecture/decisions/adrs/019-epistemic-status.md +66 -0
- data/.claude.json +11 -0
- data/.envrc +9 -7
- data/.irbrc +14 -14
- data/.reek.yml +104 -0
- data/.rubocop.yml +0 -11
- data/.ruby-version +1 -0
- data/CHANGELOG.md +160 -98
- data/README.md +22 -17
- data/SETUP.md +49 -46
- data/_typos.toml +17 -0
- data/bin/htm +18 -0
- data/db/migrate/00010_convert_embedding_to_sparsevec.rb +47 -0
- data/db/migrate/00011_strip_frontmatter_from_chunks.rb +66 -0
- data/db/migrate/00012_add_event_time_to_nodes.rb +110 -0
- data/db/migrate/00013_create_node_links.rb +158 -0
- data/db/migrate/00014_add_epistemic_status.rb +110 -0
- data/db/schema.sql +238 -7
- data/db/seed_data/README.md +11 -11
- data/db/seeds.rb +11 -11
- data/docs/api/database.md +8 -8
- data/docs/api/embedding-service.md +138 -262
- data/docs/api/htm.md +128 -12
- data/docs/api/index.md +8 -8
- data/docs/api/long-term-memory.md +8 -19
- data/docs/api/working-memory.md +34 -46
- data/docs/api/yard/HTM/Admin/Console.md +53 -0
- data/docs/api/yard/HTM/Admin/DatabaseCommands/Console.md +38 -0
- data/docs/api/yard/HTM/Admin/DatabaseCommands.md +127 -0
- data/docs/api/yard/HTM/Admin/EnrichCommands.md +85 -0
- data/docs/api/yard/HTM/Admin/Error.md +9 -0
- data/docs/api/yard/HTM/Admin/FileCommands/Console.md +50 -0
- data/docs/api/yard/HTM/Admin/FileCommands.md +83 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands/Base.md +17 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands/Edit.md +74 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands/Search.md +77 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands/TagSearch.md +46 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands/WorkingMemory.md +36 -0
- data/docs/api/yard/HTM/Admin/MemoryCommands.md +67 -0
- data/docs/api/yard/HTM/Admin/TagCommands/Console.md +48 -0
- data/docs/api/yard/HTM/Admin/TagCommands.md +105 -0
- data/docs/api/yard/HTM/Admin/TagGraph.md +149 -0
- data/docs/api/yard/HTM/Admin/YardDocs.md +60 -0
- data/docs/api/yard/HTM/Admin.md +102 -0
- data/docs/api/yard/HTM/AuthorizationError.md +6 -6
- data/docs/api/yard/HTM/CLI/ConfigFile.md +40 -0
- data/docs/api/yard/HTM/CLI/Db.md +63 -0
- data/docs/api/yard/HTM/CLI/Enrich.md +39 -0
- data/docs/api/yard/HTM/CLI/ErrorSuggestion.md +56 -0
- data/docs/api/yard/HTM/CLI/Files.md +36 -0
- data/docs/api/yard/HTM/CLI/Group/ClassMethods.md +11 -0
- data/docs/api/yard/HTM/CLI/Group.md +13 -0
- data/docs/api/yard/HTM/CLI/MemoryCommand/ClassMethods.md +20 -0
- data/docs/api/yard/HTM/CLI/MemoryCommand.md +9 -0
- data/docs/api/yard/HTM/CLI/Robots.md +31 -0
- data/docs/api/yard/HTM/CLI/Support.md +9 -0
- data/docs/api/yard/HTM/CLI/Tags.md +57 -0
- data/docs/api/yard/HTM/CLI/WorkingMemory.md +24 -0
- data/docs/api/yard/HTM/CLI.md +84 -0
- data/docs/api/yard/HTM/CircuitBreaker/Guarded.md +29 -0
- data/docs/api/yard/HTM/CircuitBreaker/Settings.md +21 -0
- data/docs/api/yard/HTM/CircuitBreaker/Status.md +42 -0
- data/docs/api/yard/HTM/CircuitBreaker.md +54 -49
- data/docs/api/yard/HTM/CircuitBreakerOpenError.md +9 -9
- data/docs/api/yard/HTM/Config/Builder.md +87 -0
- data/docs/api/yard/HTM/Config/Coercion.md +59 -0
- data/docs/api/yard/HTM/Config/Database.md +102 -0
- data/docs/api/yard/HTM/Config/Readers.md +30 -0
- data/docs/api/yard/HTM/Config/RubyLlmSettings.md +32 -0
- data/docs/api/yard/HTM/Config/Validator.md +59 -0
- data/docs/api/yard/HTM/Config.md +224 -105
- data/docs/api/yard/HTM/ConfigurationError.md +20 -0
- data/docs/api/yard/HTM/Confirmation.md +22 -0
- data/docs/api/yard/HTM/Database/Connection.md +26 -0
- data/docs/api/yard/HTM/Database/Migrations.md +32 -0
- data/docs/api/yard/HTM/Database/Report.md +26 -0
- data/docs/api/yard/HTM/Database/SchemaFile.md +52 -0
- data/docs/api/yard/HTM/Database/Teardown.md +15 -0
- data/docs/api/yard/HTM/Database.md +58 -70
- data/docs/api/yard/HTM/DatabaseDocs.md +67 -0
- data/docs/api/yard/HTM/DatabaseError.md +6 -6
- data/docs/api/yard/HTM/Deletion.md +32 -0
- data/docs/api/yard/HTM/EmbeddingError.md +6 -6
- data/docs/api/yard/HTM/EmbeddingService.md +37 -38
- data/docs/api/yard/HTM/Epistemics.md +135 -0
- data/docs/api/yard/HTM/Error.md +6 -6
- data/docs/api/yard/HTM/EventTime.md +110 -0
- data/docs/api/yard/HTM/FileMemory.md +76 -0
- data/docs/api/yard/HTM/InputValidator.md +82 -0
- data/docs/api/yard/HTM/JobAdapter/Job.md +26 -0
- data/docs/api/yard/HTM/JobAdapter.md +35 -16
- data/docs/api/yard/HTM/Jobs/FailureLogging.md +14 -0
- data/docs/api/yard/HTM/Jobs/GenerateEmbeddingJob.md +16 -0
- data/docs/api/yard/HTM/Jobs/GeneratePropositionsJob.md +17 -0
- data/docs/api/yard/HTM/Jobs/GenerateRelationshipsJob.md +26 -0
- data/docs/api/yard/HTM/Jobs/GenerateTagsJob.md +17 -0
- data/docs/api/yard/HTM/Jobs/LlmCallTimer.md +58 -0
- data/docs/api/yard/HTM/Jobs/NodeLookup.md +14 -0
- data/docs/api/yard/HTM/Jobs.md +13 -0
- data/docs/api/yard/HTM/Loaders/ChunkSync/Chunk.md +22 -0
- data/docs/api/yard/HTM/Loaders/ChunkSync.md +50 -0
- data/docs/api/yard/HTM/Loaders/MarkdownChunker/Coalescer.md +24 -0
- data/docs/api/yard/HTM/Loaders/MarkdownChunker/Packer.md +20 -0
- data/docs/api/yard/HTM/Loaders/MarkdownChunker/Splitter.md +18 -0
- data/docs/api/yard/HTM/Loaders/MarkdownChunker.md +83 -0
- data/docs/api/yard/HTM/Loaders/MarkdownLoader/Document.md +43 -0
- data/docs/api/yard/HTM/Loaders/MarkdownLoader.md +62 -0
- data/docs/api/yard/HTM/Loaders.md +5 -0
- data/docs/api/yard/HTM/LongTermMemory/FulltextSearch.md +36 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/RrfMerger.md +25 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/RrfRows.md +30 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/RrfSql/Query.md +79 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/RrfSql/Source.md +45 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/RrfSql.md +11 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch/TagDepth.md +52 -0
- data/docs/api/yard/HTM/LongTermMemory/HybridSearch.md +52 -0
- data/docs/api/yard/HTM/LongTermMemory/NodeOperations.md +95 -0
- data/docs/api/yard/HTM/LongTermMemory/RelevanceScorer/HierarchicalJaccard.md +58 -0
- data/docs/api/yard/HTM/LongTermMemory/RelevanceScorer/TagSearch.md +27 -0
- data/docs/api/yard/HTM/LongTermMemory/RelevanceScorer.md +81 -0
- data/docs/api/yard/HTM/LongTermMemory/RobotOperations.md +22 -0
- data/docs/api/yard/HTM/LongTermMemory/TagOperations/ExpiringValue.md +24 -0
- data/docs/api/yard/HTM/LongTermMemory/TagOperations/TagMatchSql.md +40 -0
- data/docs/api/yard/HTM/LongTermMemory/TagOperations.md +129 -0
- data/docs/api/yard/HTM/LongTermMemory/VectorSearch.md +30 -0
- data/docs/api/yard/HTM/LongTermMemory.md +279 -31
- data/docs/api/yard/HTM/MCP/AssembleContextTool.md +16 -0
- data/docs/api/yard/HTM/MCP/ClearGroupWorkingMemoryTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ClearWorkingMemoryTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ConfigResource.md +12 -0
- data/docs/api/yard/HTM/MCP/ConfirmTool.md +12 -0
- data/docs/api/yard/HTM/MCP/CreateGroupTool.md +12 -0
- data/docs/api/yard/HTM/MCP/EnrichPendingTool.md +16 -0
- data/docs/api/yard/HTM/MCP/ExtractPropositionsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/FailoverTool.md +12 -0
- data/docs/api/yard/HTM/MCP/FileInfoTool.md +13 -0
- data/docs/api/yard/HTM/MCP/FileSourcesResource.md +12 -0
- data/docs/api/yard/HTM/MCP/FileSupport.md +7 -0
- data/docs/api/yard/HTM/MCP/FindByTopicTool.md +12 -0
- data/docs/api/yard/HTM/MCP/FirstMentionTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ForgetContentTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ForgetTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GetGroupStatusTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GetGroupWorkingMemoryTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GetNodeTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GetRobotTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GetWorkingMemoryTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GroupRecallTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GroupRememberTool.md +12 -0
- data/docs/api/yard/HTM/MCP/GroupSession.md +23 -0
- data/docs/api/yard/HTM/MCP/JoinGroupTool.md +12 -0
- data/docs/api/yard/HTM/MCP/LeaveGroupTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ListDeletedTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ListFilesTool.md +13 -0
- data/docs/api/yard/HTM/MCP/ListGroupsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ListRobotsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ListTagsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/LoadDirectoryTool.md +13 -0
- data/docs/api/yard/HTM/MCP/LoadFileTool.md +13 -0
- data/docs/api/yard/HTM/MCP/MemoryStatsResource.md +13 -0
- data/docs/api/yard/HTM/MCP/PopularTagsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/PromoteRobotTool.md +12 -0
- data/docs/api/yard/HTM/MCP/PurgeDeletedTool.md +12 -0
- data/docs/api/yard/HTM/MCP/RecallTool.md +16 -0
- data/docs/api/yard/HTM/MCP/RecentMemoriesResource.md +13 -0
- data/docs/api/yard/HTM/MCP/RelatedNodesTool.md +12 -0
- data/docs/api/yard/HTM/MCP/RememberTool.md +12 -0
- data/docs/api/yard/HTM/MCP/RestoreTool.md +12 -0
- data/docs/api/yard/HTM/MCP/RobotGroupsResource.md +13 -0
- data/docs/api/yard/HTM/MCP/RobotTeamsStatusTool.md +13 -0
- data/docs/api/yard/HTM/MCP/RunRobotTeamsTool.md +13 -0
- data/docs/api/yard/HTM/MCP/SearchByTagsTool.md +16 -0
- data/docs/api/yard/HTM/MCP/SearchTagsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/Server.md +37 -0
- data/docs/api/yard/HTM/MCP/Session.md +32 -0
- data/docs/api/yard/HTM/MCP/SetRobotTool.md +12 -0
- data/docs/api/yard/HTM/MCP/ShutdownGroupTool.md +12 -0
- data/docs/api/yard/HTM/MCP/StartupPromptResource.md +16 -0
- data/docs/api/yard/HTM/MCP/StatsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/SyncFilesTool.md +13 -0
- data/docs/api/yard/HTM/MCP/SyncGroupTool.md +12 -0
- data/docs/api/yard/HTM/MCP/TagHierarchyResource.md +16 -0
- data/docs/api/yard/HTM/MCP/TagNodeTool.md +12 -0
- data/docs/api/yard/HTM/MCP/TagTreeTool.md +22 -0
- data/docs/api/yard/HTM/MCP/TeamNames.md +7 -0
- data/docs/api/yard/HTM/MCP/TimelineTool.md +12 -0
- data/docs/api/yard/HTM/MCP/Tool.md +24 -0
- data/docs/api/yard/HTM/MCP/ToolSupport.md +17 -0
- data/docs/api/yard/HTM/MCP/TopicRelationshipsTool.md +12 -0
- data/docs/api/yard/HTM/MCP/TransferWorkingMemoryTool.md +12 -0
- data/docs/api/yard/HTM/MCP/UnloadFileTool.md +13 -0
- data/docs/api/yard/HTM/MCP/UntagNodeTool.md +12 -0
- data/docs/api/yard/HTM/MCP.md +30 -0
- data/docs/api/yard/HTM/Migration.md +44 -0
- data/docs/api/yard/HTM/Models/FileSource.md +66 -0
- data/docs/api/yard/HTM/Models/Node/Scopes.md +74 -0
- data/docs/api/yard/HTM/Models/Node/SoftDeletion.md +22 -0
- data/docs/api/yard/HTM/Models/Node/VectorSimilarity.md +28 -0
- data/docs/api/yard/HTM/Models/Node.md +113 -0
- data/docs/api/yard/HTM/Models/NodeLink.md +65 -0
- data/docs/api/yard/HTM/Models/NodeRelationship.md +31 -0
- data/docs/api/yard/HTM/Models/NodeTag.md +38 -0
- data/docs/api/yard/HTM/Models/Robot.md +50 -0
- data/docs/api/yard/HTM/Models/RobotNode.md +35 -0
- data/docs/api/yard/HTM/Models/Tag/Scopes.md +32 -0
- data/docs/api/yard/HTM/Models/Tag.md +112 -0
- data/docs/api/yard/HTM/Models.md +5 -0
- data/docs/api/yard/HTM/NodeEnrichment.md +36 -0
- data/docs/api/yard/HTM/NodeView.md +113 -0
- data/docs/api/yard/HTM/NotFoundError.md +6 -5
- data/docs/api/yard/HTM/Observability.md +58 -40
- data/docs/api/yard/HTM/PropositionError.md +6 -6
- data/docs/api/yard/HTM/PropositionService.md +63 -29
- data/docs/api/yard/HTM/QueryCache/KeyNormalizer.md +25 -0
- data/docs/api/yard/HTM/QueryCache/NullStore.md +19 -0
- data/docs/api/yard/HTM/QueryCache/Store.md +43 -0
- data/docs/api/yard/HTM/QueryCache.md +41 -46
- data/docs/api/yard/HTM/QueryTimeoutError.md +9 -8
- data/docs/api/yard/HTM/Railtie.md +11 -7
- data/docs/api/yard/HTM/RecallQuery.md +111 -0
- data/docs/api/yard/HTM/ResourceExhaustedError.md +6 -6
- data/docs/api/yard/HTM/RobotGroup/CacheSync.md +35 -0
- data/docs/api/yard/HTM/RobotGroup/Membership.md +96 -0
- data/docs/api/yard/HTM/RobotGroup/TransferOptions.md +14 -0
- data/docs/api/yard/HTM/RobotGroup/WorkingMemoryLedger.md +65 -0
- data/docs/api/yard/HTM/RobotGroup.md +116 -360
- data/docs/api/yard/HTM/Robots/Actions/TagMove.md +31 -0
- data/docs/api/yard/HTM/Robots/Actions.md +153 -0
- data/docs/api/yard/HTM/Robots/Neighbors.md +20 -0
- data/docs/api/yard/HTM/Robots/Supervisor/Idler.md +26 -0
- data/docs/api/yard/HTM/Robots/Supervisor/Roster.md +26 -0
- data/docs/api/yard/HTM/Robots/Supervisor.md +42 -0
- data/docs/api/yard/HTM/Robots/Team.md +60 -0
- data/docs/api/yard/HTM/Robots/Teams/Archivist.md +43 -0
- data/docs/api/yard/HTM/Robots/Teams/Consolidator.md +29 -0
- data/docs/api/yard/HTM/Robots/Teams/ContradictionDetector.md +33 -0
- data/docs/api/yard/HTM/Robots/Teams/TagCurator.md +37 -0
- data/docs/api/yard/HTM/Robots/Teams.md +5 -0
- data/docs/api/yard/HTM/Robots/Tools/ArchiveNodes.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools/Base.md +16 -0
- data/docs/api/yard/HTM/Robots/Tools/MergeNodes.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools/MergeTags.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools/Pass.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools/RecordConflict.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools/SupersedeNode.md +12 -0
- data/docs/api/yard/HTM/Robots/Tools.md +14 -0
- data/docs/api/yard/HTM/Robots.md +72 -0
- data/docs/api/yard/HTM/SearchFilters.md +82 -0
- data/docs/api/yard/HTM/SequelConfig.md +97 -0
- data/docs/api/yard/HTM/Settings.md +39 -0
- data/docs/api/yard/HTM/Sinatra/Helpers.md +37 -0
- data/docs/api/yard/HTM/Sinatra/Middleware.md +29 -0
- data/docs/api/yard/HTM/Sinatra.md +44 -0
- data/docs/api/yard/HTM/SqlBuilder/Sparsevec.md +69 -0
- data/docs/api/yard/HTM/SqlBuilder.md +62 -75
- data/docs/api/yard/HTM/StartupPrompt.md +45 -0
- data/docs/api/yard/HTM/TagError.md +6 -6
- data/docs/api/yard/HTM/TagService.md +100 -37
- data/docs/api/yard/HTM/TagTree/Branch.md +43 -0
- data/docs/api/yard/HTM/TagTree/SvgRenderer/Layout.md +51 -0
- data/docs/api/yard/HTM/TagTree/SvgRenderer.md +25 -0
- data/docs/api/yard/HTM/TagTree.md +65 -0
- data/docs/api/yard/HTM/Telemetry/NullInstrument.md +12 -9
- data/docs/api/yard/HTM/Telemetry/NullMeter.md +17 -9
- data/docs/api/yard/HTM/Telemetry.md +53 -50
- data/docs/api/yard/HTM/Timeframe/Result.md +13 -16
- data/docs/api/yard/HTM/Timeframe.md +17 -20
- data/docs/api/yard/HTM/TimeframeExtractor/Patterns.md +18 -0
- data/docs/api/yard/HTM/TimeframeExtractor/Result.md +13 -16
- data/docs/api/yard/HTM/TimeframeExtractor.md +27 -16
- data/docs/api/yard/HTM/Timeline.md +113 -0
- data/docs/api/yard/HTM/ValidationError.md +6 -5
- data/docs/api/yard/HTM/Workflows/RememberWorkflow/NodeState.md +73 -0
- data/docs/api/yard/HTM/Workflows/RememberWorkflow.md +80 -0
- data/docs/api/yard/HTM/Workflows.md +5 -0
- data/docs/api/yard/HTM/WorkingMemory/Entry.md +67 -0
- data/docs/api/yard/HTM/WorkingMemory/Store.md +54 -0
- data/docs/api/yard/HTM/WorkingMemory.md +113 -87
- data/docs/api/yard/HTM/WorkingMemoryChannel/Subscribers.md +28 -0
- data/docs/api/yard/HTM/WorkingMemoryChannel.md +108 -102
- data/docs/api/yard/HTM.md +483 -5
- data/docs/api/yard/README.md +211 -0
- data/docs/api/yard/Sinatra/Base.md +30 -0
- data/docs/api/yard/Sinatra.md +7 -0
- data/docs/api/yard/index.csv +1834 -181
- data/docs/api/yard-reference.md +228 -9
- data/docs/architecture/adrs/005-rag-retrieval.md +3 -0
- data/docs/architecture/adrs/index.md +1 -1
- data/docs/architecture/index.md +2 -2
- data/docs/architecture/overview.md +3 -3
- data/docs/assets/images/project-structure.svg +2 -2
- data/docs/database/INDEX.md +113 -0
- data/docs/database/README.md +60 -176
- data/docs/database/file_sources.md +51 -0
- data/docs/database/file_sources.svg +120 -0
- data/docs/database/naming-convention.md +12 -12
- data/docs/database/node_links.md +65 -0
- data/docs/database/node_links.svg +171 -0
- data/docs/database/node_relationships.md +62 -0
- data/docs/database/node_relationships.svg +124 -0
- data/docs/database/node_tags.md +50 -0
- data/docs/database/node_tags.svg +125 -0
- data/docs/database/nodes.md +120 -0
- data/docs/database/nodes.svg +394 -0
- data/docs/database/robot_nodes.md +57 -0
- data/docs/database/robot_nodes.svg +155 -0
- data/docs/database/robots.md +40 -0
- data/docs/database/robots.svg +131 -0
- data/docs/database/schema.svg +384 -275
- data/docs/database/schema_migrations.md +19 -0
- data/docs/database/schema_migrations.svg +31 -0
- data/docs/database/tags.md +47 -0
- data/docs/database/tags.svg +90 -0
- data/docs/development/asgard-tasks.md +114 -0
- data/docs/development/contributing.md +6 -6
- data/docs/development/index.md +15 -17
- data/docs/development/schema.md +43 -14
- data/docs/development/setup.md +60 -70
- data/docs/development/testing.md +57 -65
- data/docs/examples/basic-usage.md +9 -9
- data/docs/examples/config-files.md +8 -8
- data/docs/examples/file-loading.md +12 -12
- data/docs/examples/index.md +15 -8
- data/docs/examples/llm-configuration.md +13 -9
- data/docs/examples/mcp-client.md +61 -59
- data/docs/examples/rails-integration.md +5 -4
- data/docs/examples/sinatra-integration.md +5 -4
- data/docs/examples/standalone-app.md +17 -16
- data/docs/getting-started/index.md +3 -3
- data/docs/getting-started/installation.md +76 -83
- data/docs/getting-started/quick-start.md +24 -22
- data/docs/guides/adding-memories.md +14 -3
- data/docs/guides/cli.md +458 -0
- data/docs/guides/configuration.md +72 -37
- data/docs/guides/epistemic-status.md +138 -0
- data/docs/guides/event-time.md +106 -0
- data/docs/guides/file-loading.md +26 -22
- data/docs/guides/getting-started.md +21 -17
- data/docs/guides/long-term-memory.md +1 -1
- data/docs/guides/mcp-server.md +416 -173
- data/docs/guides/propositions.md +18 -29
- data/docs/guides/recalling-memories.md +22 -7
- data/docs/guides/robot-teams.md +96 -0
- data/docs/guides/search-strategies.md +10 -7
- data/docs/guides/tags.md +19 -19
- data/docs/guides/timeline.md +106 -0
- data/docs/index.md +7 -7
- data/docs/llms.txt +35 -0
- data/docs/multi_framework_support.md +13 -13
- data/docs/robots/robot-groups.md +9 -9
- data/docs/robots/two-tier-memory.md +13 -26
- data/docs/setup_local_database.md +33 -31
- data/examples/00_create_examples_db.rb +20 -7
- data/examples/01_basic_usage.rb +20 -18
- data/examples/02_config_file_example/README.md +13 -12
- data/examples/02_config_file_example/config/htm.local.yml +8 -8
- data/examples/02_config_file_example/show_config.rb +3 -4
- data/examples/03_custom_llm_configuration.rb +12 -12
- data/examples/04_file_loader_usage.rb +15 -21
- data/examples/05_timeframe_demo.rb +282 -234
- data/examples/06_example_app/.loki +36 -0
- data/examples/06_example_app/app.rb +21 -33
- data/examples/07_cli_app/README.md +18 -18
- data/examples/07_cli_app/htm_cli.rb +25 -19
- data/examples/08_sinatra_app/Gemfile +1 -0
- data/examples/08_sinatra_app/Gemfile.lock +101 -67
- data/examples/08_sinatra_app/app.rb +64 -62
- data/examples/09_mcp_client.rb +92 -119
- data/examples/10_telemetry/README.md +3 -3
- data/examples/10_telemetry/SETUP_README.md +2 -2
- data/examples/10_telemetry/demo.rb +5 -5
- data/examples/11_robot_groups/README.md +5 -4
- data/examples/11_robot_groups/lib/robot_worker.rb +0 -5
- data/examples/11_robot_groups/multi_process.rb +5 -4
- data/examples/11_robot_groups/same_process.rb +18 -17
- data/examples/12_rails_app/Gemfile +1 -1
- data/examples/12_rails_app/Gemfile.lock +146 -97
- data/examples/12_rails_app/README.md +21 -17
- data/examples/12_rails_app/app/controllers/chats_controller.rb +33 -63
- data/examples/12_rails_app/app/controllers/memories_controller.rb +7 -1
- data/examples/12_rails_app/app/controllers/messages_controller.rb +21 -58
- data/examples/12_rails_app/app/controllers/search_controller.rb +7 -2
- data/examples/12_rails_app/app/models/chat.rb +0 -33
- data/examples/12_rails_app/app/models/message.rb +0 -2
- data/examples/12_rails_app/app/views/chats/show.html.erb +2 -2
- data/examples/12_rails_app/app/views/files/new.html.erb +1 -1
- data/examples/12_rails_app/app/views/memories/_memory_card.html.erb +1 -1
- data/examples/12_rails_app/app/views/memories/new.html.erb +12 -0
- data/examples/12_rails_app/app/views/memories/show.html.erb +13 -0
- data/examples/12_rails_app/app/views/search/index.html.erb +18 -2
- data/examples/12_rails_app/config/initializers/ruby_llm.rb +11 -15
- data/examples/12_rails_app/db/migrate/20261205061932_create_ruby_llm_records.rb +160 -0
- data/examples/12_rails_app/db/migrate/20261205061933_create_chats.rb +13 -0
- data/examples/12_rails_app/db/migrate/20261205061934_create_messages.rb +23 -0
- data/examples/12_rails_app/db/schema.rb +163 -20
- data/examples/README.md +53 -44
- data/examples/examples_helper.rb +29 -5
- data/htm.gemspec +68 -0
- data/lib/htm/admin/database_commands.rb +454 -0
- data/lib/htm/admin/enrich_commands.rb +209 -0
- data/lib/htm/admin/file_commands.rb +323 -0
- data/lib/htm/admin/memory_commands/edit.rb +157 -0
- data/lib/htm/admin/memory_commands/search.rb +178 -0
- data/lib/htm/admin/memory_commands/tag_search.rb +98 -0
- data/lib/htm/admin/memory_commands/text.rb +164 -0
- data/lib/htm/admin/memory_commands/working_memory.rb +71 -0
- data/lib/htm/admin/memory_commands.rb +179 -0
- data/lib/htm/admin/tag_commands.rb +352 -0
- data/lib/htm/admin/tag_graph.rb +290 -0
- data/lib/htm/admin/templates/tag_graph.html +295 -0
- data/lib/htm/admin/yard_docs.rb +206 -0
- data/lib/htm/admin.rb +253 -0
- data/lib/htm/circuit_breaker.rb +142 -68
- data/lib/htm/class_methods.rb +136 -0
- data/lib/htm/cli/config_file.rb +86 -0
- data/lib/htm/cli/db.rb +77 -0
- data/lib/htm/cli/enrich.rb +44 -0
- data/lib/htm/cli/environment.rb +74 -0
- data/lib/htm/cli/error_suggestion.rb +97 -0
- data/lib/htm/cli/files.rb +41 -0
- data/lib/htm/cli/group.rb +32 -0
- data/lib/htm/cli/memory.rb +320 -0
- data/lib/htm/cli/memory_command.rb +71 -0
- data/lib/htm/cli/robots.rb +71 -0
- data/lib/htm/cli/support.rb +46 -0
- data/lib/htm/cli/tags.rb +103 -0
- data/lib/htm/cli/working_memory.rb +41 -0
- data/lib/htm/cli.rb +75 -0
- data/lib/htm/config/builder.rb +99 -68
- data/lib/htm/config/coercion.rb +91 -0
- data/lib/htm/config/database.rb +81 -52
- data/lib/htm/config/defaults.yml +52 -16
- data/lib/htm/config/readers.rb +85 -0
- data/lib/htm/config/ruby_llm_settings.rb +58 -0
- data/lib/htm/config/validator.rb +45 -26
- data/lib/htm/config.rb +112 -297
- data/lib/htm/database.rb +305 -396
- data/lib/htm/database_docs.rb +149 -0
- data/lib/htm/embedding_service.rb +26 -66
- data/lib/htm/epistemics.rb +254 -0
- data/lib/htm/errors.rb +4 -4
- data/lib/htm/event_time.rb +201 -0
- data/lib/htm/file_memory.rb +106 -0
- data/lib/htm/input_validator.rb +158 -0
- data/lib/htm/integrations/sinatra.rb +43 -31
- data/lib/htm/job_adapter.rb +78 -83
- data/lib/htm/jobs/failure_logging.rb +49 -0
- data/lib/htm/jobs/generate_embedding_job.rb +21 -28
- data/lib/htm/jobs/generate_propositions_job.rb +56 -28
- data/lib/htm/jobs/generate_relationships_job.rb +28 -24
- data/lib/htm/jobs/generate_tags_job.rb +32 -37
- data/lib/htm/jobs/llm_call_timer.rb +53 -0
- data/lib/htm/jobs/node_lookup.rb +27 -0
- data/lib/htm/knowledge_memory.rb +153 -0
- data/lib/htm/loaders/chunk_sync.rb +168 -0
- data/lib/htm/loaders/markdown_chunker.rb +207 -36
- data/lib/htm/loaders/markdown_loader.rb +76 -120
- data/lib/htm/long_term_memory/fulltext_search.rb +15 -36
- data/lib/htm/long_term_memory/hybrid_search.rb +471 -544
- data/lib/htm/long_term_memory/node_operations.rb +110 -81
- data/lib/htm/long_term_memory/relevance_scorer.rb +232 -237
- data/lib/htm/long_term_memory/tag_operations.rb +201 -130
- data/lib/htm/long_term_memory/vector_search.rb +33 -61
- data/lib/htm/long_term_memory.rb +5 -17
- data/lib/htm/mcp/file_tools.rb +190 -0
- data/lib/htm/mcp/group_tools.rb +223 -233
- data/lib/htm/mcp/node_tools.rb +350 -0
- data/lib/htm/mcp/resources.rb +102 -28
- data/lib/htm/mcp/robot_team_tools.rb +119 -0
- data/lib/htm/mcp/server.rb +26 -14
- data/lib/htm/mcp/tag_tools.rb +130 -0
- data/lib/htm/mcp/tool.rb +40 -0
- data/lib/htm/mcp/tool_support.rb +88 -0
- data/lib/htm/mcp/tools.rb +232 -283
- data/lib/htm/models/file_source.rb +35 -20
- data/lib/htm/models/node.rb +287 -193
- data/lib/htm/models/node_link.rb +97 -0
- data/lib/htm/models/node_relationship.rb +3 -2
- data/lib/htm/models/node_tag.rb +22 -2
- data/lib/htm/models/robot.rb +4 -8
- data/lib/htm/models/robot_node.rb +5 -2
- data/lib/htm/models/tag.rb +53 -207
- data/lib/htm/node_enrichment.rb +75 -0
- data/lib/htm/node_view.rb +295 -0
- data/lib/htm/observability.rb +114 -98
- data/lib/htm/proposition_service.rb +38 -74
- data/lib/htm/query_cache.rb +145 -91
- data/lib/htm/railtie.rb +3 -7
- data/lib/htm/request_options.rb +149 -0
- data/lib/htm/robot_group/cache_sync.rb +69 -0
- data/lib/htm/robot_group/membership.rb +147 -0
- data/lib/htm/robot_group/working_memory_ledger.rb +111 -0
- data/lib/htm/robot_group.rb +128 -521
- data/lib/htm/robots/actions.rb +371 -0
- data/lib/htm/robots/neighbors.rb +63 -0
- data/lib/htm/robots/node_brief.rb +49 -0
- data/lib/htm/robots/supervisor.rb +140 -0
- data/lib/htm/robots/team.rb +124 -0
- data/lib/htm/robots/teams/archivist.rb +88 -0
- data/lib/htm/robots/teams/consolidator.rb +52 -0
- data/lib/htm/robots/teams/contradiction_detector.rb +67 -0
- data/lib/htm/robots/teams/tag_curator.rb +75 -0
- data/lib/htm/robots/tools.rb +127 -0
- data/lib/htm/robots.rb +125 -0
- data/lib/htm/search_filters.rb +116 -0
- data/lib/htm/sequel_config.rb +95 -59
- data/lib/htm/sql_builder.rb +162 -53
- data/lib/htm/startup_prompt.rb +73 -0
- data/lib/htm/tag_service.rb +104 -109
- data/lib/htm/tag_tree.rb +206 -0
- data/lib/htm/telemetry.rb +15 -16
- data/lib/htm/timeframe.rb +27 -9
- data/lib/htm/timeframe_extractor.rb +77 -55
- data/lib/htm/timeline.rb +230 -0
- data/lib/htm/version.rb +1 -1
- data/lib/htm/workflows/remember_workflow.rb +145 -136
- data/lib/htm/working_memory/entry.rb +53 -0
- data/lib/htm/working_memory/store.rb +97 -0
- data/lib/htm/working_memory.rb +137 -139
- data/lib/htm/working_memory_channel.rb +90 -40
- data/lib/htm.rb +177 -501
- data/mkdocs.yml +100 -23
- data/scripts/install_local_database.sh +7 -6
- metadata +1032 -594
- data/.tbls.yml +0 -31
- data/Rakefile +0 -240
- data/bin/htm_mcp +0 -27
- data/docs/api/yard/HTM/ActiveRecordConfig.md +0 -29
- data/docs/api/yard/HTM/ConfigSection.md +0 -28
- data/docs/database/public.file_sources.md +0 -42
- data/docs/database/public.file_sources.svg +0 -219
- data/docs/database/public.node_stats.md +0 -48
- data/docs/database/public.node_stats.svg +0 -41
- data/docs/database/public.node_tags.md +0 -41
- data/docs/database/public.node_tags.svg +0 -251
- data/docs/database/public.nodes.md +0 -61
- data/docs/database/public.nodes.svg +0 -283
- data/docs/database/public.nodes_tags.md +0 -39
- data/docs/database/public.nodes_tags.svg +0 -112
- data/docs/database/public.ontology_structure.md +0 -48
- data/docs/database/public.ontology_structure.svg +0 -38
- data/docs/database/public.operations_log.md +0 -42
- data/docs/database/public.operations_log.svg +0 -130
- data/docs/database/public.relationships.md +0 -39
- data/docs/database/public.relationships.svg +0 -41
- data/docs/database/public.robot_activity.md +0 -46
- data/docs/database/public.robot_activity.svg +0 -35
- data/docs/database/public.robot_nodes.md +0 -48
- data/docs/database/public.robot_nodes.svg +0 -251
- data/docs/database/public.robots.md +0 -34
- data/docs/database/public.robots.svg +0 -165
- data/docs/database/public.schema_migrations.md +0 -29
- data/docs/database/public.schema_migrations.svg +0 -26
- data/docs/database/public.tags.md +0 -38
- data/docs/database/public.tags.svg +0 -147
- data/docs/database/public.topic_relationships.md +0 -45
- data/docs/database/public.topic_relationships.svg +0 -32
- data/docs/database/schema.json +0 -1814
- data/docs/database_rake_tasks.md +0 -345
- data/docs/development/rake-tasks.md +0 -1113
- data/docs/using_rake_tasks_in_your_app.md +0 -383
- data/examples/06_example_app/Rakefile +0 -71
- data/examples/12_rails_app/app/models/model.rb +0 -5
- data/examples/12_rails_app/app/models/tool_call.rb +0 -5
- data/examples/12_rails_app/db/migrate/20250124000001_create_ruby_llm_tables.rb +0 -34
- data/examples/12_rails_app/db/migrate/20250124000002_create_models_table.rb +0 -28
- data/lib/htm/mcp/cli.rb +0 -583
- data/lib/htm/tasks.rb +0 -79
- data/lib/tasks/db.rake +0 -15
- data/lib/tasks/doc.rake +0 -301
- data/lib/tasks/files.rake +0 -285
- data/lib/tasks/htm.rake +0 -703
- data/lib/tasks/jobs.rake +0 -429
- data/lib/tasks/tags.rake +0 -184
- data/scripts/backfill_parent_tags.rb +0 -376
- data/scripts/normalize_plural_tags.rb +0 -335
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Module HTM::Robots <a id="module-HTM-Robots"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Defined in** | lib/htm/robots.rb, lib/htm/robots/team.rb, lib/htm/robots/tools.rb, lib/htm/robots/actions.rb, lib/htm/robots/neighbors.rb, lib/htm/robots/supervisor.rb, lib/htm/robots/teams/archivist.rb, lib/htm/robots/teams/tag_curator.rb, lib/htm/robots/teams/consolidator.rb, lib/htm/robots/teams/contradiction_detector.rb |
|
|
6
|
+
|
|
7
|
+
Background robot teams (built on robot_lab) that keep long-term memory in
|
|
8
|
+
shape. They act directly; removals are soft deletes.
|
|
9
|
+
|
|
10
|
+
* tag_curator: merges duplicate tags in the hierarchy
|
|
11
|
+
* consolidator: merges near-duplicate memories
|
|
12
|
+
* contradiction_detector: retires memories newer ones contradict
|
|
13
|
+
* archivist: replaces cold memories with digests
|
|
14
|
+
|
|
15
|
+
**@example Constant attention in a long-running process**
|
|
16
|
+
```ruby
|
|
17
|
+
supervisor = HTM::Robots.start # background thread
|
|
18
|
+
...
|
|
19
|
+
HTM::Robots.stop
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
**@example One pass, in the foreground**
|
|
23
|
+
```ruby
|
|
24
|
+
HTM::Robots.supervisor.cycle
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Public Class Methods
|
|
28
|
+
### `deep_symbolize(value)` <a id="method-c-deep_symbolize"></a> <a id="deep_symbolize-class_method"></a>
|
|
29
|
+
Not documented.
|
|
30
|
+
|
|
31
|
+
### `run_until(stop, names: nil, poll: 0.5)` <a id="method-c-run_until"></a> <a id="run_until-class_method"></a>
|
|
32
|
+
Runs the teams in the foreground until `stop` returns true; the supervisor
|
|
33
|
+
works in its own thread so a signal handler only has to flip a flag (Queue and
|
|
34
|
+
Thread#join are not allowed in trap context)
|
|
35
|
+
- **`@param`** `names` [Array<String>, nil] teams to run (default: configured)
|
|
36
|
+
- **`@param`** `stop` [#call] polled every +poll+ seconds
|
|
37
|
+
- **`@return`** [Supervisor]
|
|
38
|
+
|
|
39
|
+
### `running()` <a id="method-c-running"></a> <a id="running-class_method"></a>
|
|
40
|
+
Not documented.
|
|
41
|
+
|
|
42
|
+
### `settings(config = HTM.config)` <a id="method-c-settings"></a> <a id="settings-class_method"></a>
|
|
43
|
+
Robot settings from HTM.config.robots, as a symbol-keyed Hash with the team
|
|
44
|
+
sections nested; the robot model falls back to the tag model
|
|
45
|
+
- **`@param`** `config` [HTM::Config]
|
|
46
|
+
- **`@return`** [Hash]
|
|
47
|
+
|
|
48
|
+
### `start(names = nil)` <a id="method-c-start"></a> <a id="start-class_method"></a>
|
|
49
|
+
Starts the process-wide supervisor in a background thread
|
|
50
|
+
- **`@return`** [Supervisor]
|
|
51
|
+
|
|
52
|
+
### `status(names = nil, limit: 1000)` <a id="method-c-status"></a> <a id="status-class_method"></a>
|
|
53
|
+
Cases waiting per team, found by SQL only (no LLM calls)
|
|
54
|
+
- **`@return`** [Hash{String => Integer}]
|
|
55
|
+
|
|
56
|
+
### `stop()` <a id="method-c-stop"></a> <a id="stop-class_method"></a>
|
|
57
|
+
Not documented.
|
|
58
|
+
|
|
59
|
+
### `supervisor(names = nil, settings: self.settings)` <a id="method-c-supervisor"></a> <a id="supervisor-class_method"></a>
|
|
60
|
+
Not documented.
|
|
61
|
+
|
|
62
|
+
### `team_class(name)` <a id="method-c-team_class"></a> <a id="team_class-class_method"></a>
|
|
63
|
+
The Team class for a slug
|
|
64
|
+
- **`@raise`** [ArgumentError] for an unknown team
|
|
65
|
+
|
|
66
|
+
### `team_classes()` <a id="method-c-team_classes"></a> <a id="team_classes-class_method"></a>
|
|
67
|
+
Not documented.
|
|
68
|
+
|
|
69
|
+
### `teams(names = nil, settings: self.settings)` <a id="method-c-teams"></a> <a id="teams-class_method"></a>
|
|
70
|
+
Builds the named teams, or the configured ones when no names are given
|
|
71
|
+
- **`@param`** `names` [Array<String,Symbol>, nil]
|
|
72
|
+
- **`@return`** [Array<Team>]
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
# Class HTM::SearchFilters <a id="class-HTM-SearchFilters"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Inherits** | Data |
|
|
6
|
+
| **Defined in** | lib/htm/search_filters.rb |
|
|
7
|
+
|
|
8
|
+
The filters every search applies, beyond its query: a timeframe, a metadata
|
|
9
|
+
containment, which time axis the timeframe reads, and a point in time the
|
|
10
|
+
memories must have been valid at.
|
|
11
|
+
|
|
12
|
+
Time axes:
|
|
13
|
+
* :event (default) - when the memory happened. A node matches a range when
|
|
14
|
+
its span [occurred_at, occurred_until] overlaps it, so a digest covering
|
|
15
|
+
March is found by a search for mid-March.
|
|
16
|
+
* :recorded - when HTM stored the node (created_at)
|
|
17
|
+
|
|
18
|
+
as_of keeps only nodes whose state was true at that moment:
|
|
19
|
+
COALESCE(valid_from, occurred_at) <= as_of, and valid_until NULL or later.
|
|
20
|
+
|
|
21
|
+
statuses keeps only nodes with one of those epistemic statuses; min_confidence
|
|
22
|
+
keeps nodes rated at least that confident (an unrated node counts as 1.0).
|
|
23
|
+
|
|
24
|
+
**`@example`**
|
|
25
|
+
```ruby
|
|
26
|
+
filters = HTM::SearchFilters.build(timeframe: range, as_of: Time.utc(2026, 3, 1))
|
|
27
|
+
filters.conditions(table_alias: 'n') # => ["(...)", "(...)"]
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Attributes
|
|
31
|
+
### `as_of` [R] <a id="attribute-i-as_of"></a> <a id="as_of-instance_method"></a>
|
|
32
|
+
Returns the value of attribute as_of
|
|
33
|
+
- **`@return`** [Object] the current value of as_of
|
|
34
|
+
|
|
35
|
+
### `metadata` [R] <a id="attribute-i-metadata"></a> <a id="metadata-instance_method"></a>
|
|
36
|
+
Returns the value of attribute metadata
|
|
37
|
+
- **`@return`** [Object] the current value of metadata
|
|
38
|
+
|
|
39
|
+
### `min_confidence` [R] <a id="attribute-i-min_confidence"></a> <a id="min_confidence-instance_method"></a>
|
|
40
|
+
Returns the value of attribute min_confidence
|
|
41
|
+
- **`@return`** [Object] the current value of min_confidence
|
|
42
|
+
|
|
43
|
+
### `statuses` [R] <a id="attribute-i-statuses"></a> <a id="statuses-instance_method"></a>
|
|
44
|
+
Returns the value of attribute statuses
|
|
45
|
+
- **`@return`** [Object] the current value of statuses
|
|
46
|
+
|
|
47
|
+
### `time_axis` [R] <a id="attribute-i-time_axis"></a> <a id="time_axis-instance_method"></a>
|
|
48
|
+
Returns the value of attribute time_axis
|
|
49
|
+
- **`@return`** [Object] the current value of time_axis
|
|
50
|
+
|
|
51
|
+
### `timeframe` [R] <a id="attribute-i-timeframe"></a> <a id="timeframe-instance_method"></a>
|
|
52
|
+
Returns the value of attribute timeframe
|
|
53
|
+
- **`@return`** [Object] the current value of timeframe
|
|
54
|
+
|
|
55
|
+
## Public Class Methods
|
|
56
|
+
### `build(timeframe: nil, metadata: {}, time_axis: :event, as_of: nil, statuses: nil, min_confidence: nil)` <a id="method-c-build"></a> <a id="build-class_method"></a>
|
|
57
|
+
- **`@param`** `timeframe` [nil, Range, Array<Range>] normalized time range(s)
|
|
58
|
+
- **`@param`** `metadata` [Hash, nil] metadata the node must contain
|
|
59
|
+
- **`@param`** `time_axis` [Symbol, String] :event or :recorded
|
|
60
|
+
- **`@param`** `as_of` [Time, nil] moment the node's state must have been valid
|
|
61
|
+
- **`@param`** `statuses` [Array<String>, nil] epistemic statuses to keep (nil keeps all)
|
|
62
|
+
- **`@param`** `min_confidence` [Float, nil] lowest confidence to keep
|
|
63
|
+
- **`@raise`** [ArgumentError] for an unknown time axis
|
|
64
|
+
- **`@return`** [SearchFilters]
|
|
65
|
+
|
|
66
|
+
### `none()` <a id="method-c-none"></a> <a id="none-class_method"></a>
|
|
67
|
+
- **`@return`** [SearchFilters] filters that keep every active node
|
|
68
|
+
|
|
69
|
+
## Public Instance Methods
|
|
70
|
+
### `and_sql(table_alias: nil)` <a id="method-i-and_sql"></a> <a id="and_sql-instance_method"></a>
|
|
71
|
+
- **`@return`** [String] the conditions as an "AND ..." suffix; "" without any
|
|
72
|
+
|
|
73
|
+
### `cache_key()` <a id="method-i-cache_key"></a> <a id="cache_key-instance_method"></a>
|
|
74
|
+
- **`@return`** [Array] values identifying these filters in a cache key
|
|
75
|
+
|
|
76
|
+
### `conditions(table_alias: nil)` <a id="method-i-conditions"></a> <a id="conditions-instance_method"></a>
|
|
77
|
+
SQL conditions to AND into a WHERE clause
|
|
78
|
+
- **`@param`** `table_alias` [String, nil] alias of the nodes table
|
|
79
|
+
- **`@return`** [Array<String>]
|
|
80
|
+
|
|
81
|
+
### `time_column()` <a id="method-i-time_column"></a> <a id="time_column-instance_method"></a>
|
|
82
|
+
- **`@return`** [String] the column results are ordered and aged by
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
# Module HTM::SequelConfig <a id="module-HTM-SequelConfig"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Defined in** | lib/htm/sequel_config.rb |
|
|
6
|
+
|
|
7
|
+
Sequel database configuration and model loading
|
|
8
|
+
|
|
9
|
+
Uses HTM::Config for database settings. Configuration can come from:
|
|
10
|
+
* Environment variables (HTM_DATABASE__URL, HTM_DATABASE__HOST, etc.)
|
|
11
|
+
* Programmatic configuration via HTM.configure
|
|
12
|
+
|
|
13
|
+
Each fiber checks out its own pooled connection (the fiber_concurrency
|
|
14
|
+
extension), so the fiber job backend can run jobs concurrently.
|
|
15
|
+
|
|
16
|
+
## Constants
|
|
17
|
+
### `DEFAULT_POOL_TIMEOUT` <a id="constant-DEFAULT_POOL_TIMEOUT"></a> <a id="DEFAULT_POOL_TIMEOUT-constant"></a>
|
|
18
|
+
Wait (ms) for a free pooled connection when database.timeout is not set
|
|
19
|
+
|
|
20
|
+
### `DEFAULT_STATEMENT_TIMEOUT` <a id="constant-DEFAULT_STATEMENT_TIMEOUT"></a> <a id="DEFAULT_STATEMENT_TIMEOUT-constant"></a>
|
|
21
|
+
Statement timeout (ms) when database.statement_timeout is not set
|
|
22
|
+
|
|
23
|
+
### `MODEL_LOADING` <a id="constant-MODEL_LOADING"></a> <a id="MODEL_LOADING-constant"></a>
|
|
24
|
+
What establish_connection! does with the models once connected, by its
|
|
25
|
+
load_models: value. false leaves them unloaded (migrations on a fresh
|
|
26
|
+
database); any other value loads them once their tables exist.
|
|
27
|
+
|
|
28
|
+
## Attributes
|
|
29
|
+
### `db` [R] <a id="attribute-c-db"></a> <a id="db-class_method"></a>
|
|
30
|
+
Database connection instance
|
|
31
|
+
- **`@return`** [Sequel::Database, nil]
|
|
32
|
+
|
|
33
|
+
## Public Class Methods
|
|
34
|
+
### `build_connection_string(config)` <a id="method-c-build_connection_string"></a> <a id="build_connection_string-class_method"></a>
|
|
35
|
+
Build connection string from config hash
|
|
36
|
+
- **`@param`** `config` [Hash] Database configuration
|
|
37
|
+
- **`@return`** [String] PostgreSQL connection string
|
|
38
|
+
|
|
39
|
+
### `connected?()` <a id="method-c-connected-3F"></a> <a id="connected?-class_method"></a>
|
|
40
|
+
Check if connection is established and active
|
|
41
|
+
- **`@return`** [Boolean]
|
|
42
|
+
|
|
43
|
+
### `connection_stats()` <a id="method-c-connection_stats"></a> <a id="connection_stats-class_method"></a>
|
|
44
|
+
Get connection pool statistics
|
|
45
|
+
- **`@return`** [Hash] Pool statistics
|
|
46
|
+
|
|
47
|
+
### `disconnect!()` <a id="method-c-disconnect-21"></a> <a id="disconnect!-class_method"></a>
|
|
48
|
+
Close all database connections
|
|
49
|
+
- **`@return`** [void]
|
|
50
|
+
|
|
51
|
+
### `ensure_models_loaded!()` <a id="method-c-ensure_models_loaded-21"></a> <a id="ensure_models_loaded!-class_method"></a>
|
|
52
|
+
Ensure models are loaded
|
|
53
|
+
|
|
54
|
+
Call this after migrations to ensure models are available
|
|
55
|
+
- **`@return`** [void]
|
|
56
|
+
|
|
57
|
+
### `establish_connection!(load_models: nil)` <a id="method-c-establish_connection-21"></a> <a id="establish_connection!-class_method"></a>
|
|
58
|
+
Establish database connection from HTM::Config
|
|
59
|
+
- **`@param`** `load_models` [Boolean, nil] false to skip loading the models
|
|
60
|
+
after connecting (when running migrations on a fresh database);
|
|
61
|
+
loaded otherwise
|
|
62
|
+
- **`@return`** [Sequel::Database] The database connection
|
|
63
|
+
|
|
64
|
+
### `execute(sql)` <a id="method-c-execute"></a> <a id="execute-class_method"></a>
|
|
65
|
+
Run raw SQL
|
|
66
|
+
- **`@param`** `sql` [String] SQL to execute
|
|
67
|
+
- **`@return`** [void]
|
|
68
|
+
|
|
69
|
+
### `load_database_config()` <a id="method-c-load_database_config"></a> <a id="load_database_config-class_method"></a>
|
|
70
|
+
Load database configuration from HTM::Config
|
|
71
|
+
- **`@return`** [Hash] Database configuration hash
|
|
72
|
+
|
|
73
|
+
### `models_loadable?()` <a id="method-c-models_loadable-3F"></a> <a id="models_loadable?-class_method"></a>
|
|
74
|
+
Check if models can be loaded (tables exist)
|
|
75
|
+
- **`@return`** [Boolean]
|
|
76
|
+
|
|
77
|
+
### `pool_timeout(config)` <a id="method-c-pool_timeout"></a> <a id="pool_timeout-class_method"></a>
|
|
78
|
+
Seconds to wait for a free pooled connection
|
|
79
|
+
- **`@param`** `config` [Hash] Database configuration (timeout: in ms)
|
|
80
|
+
- **`@return`** [Float]
|
|
81
|
+
|
|
82
|
+
### `select_value(sql)` <a id="method-c-select_value"></a> <a id="select_value-class_method"></a>
|
|
83
|
+
Select a single value
|
|
84
|
+
- **`@param`** `sql` [String] SQL query
|
|
85
|
+
- **`@return`** [Object] The value
|
|
86
|
+
|
|
87
|
+
### `session_sqls(config)` <a id="method-c-session_sqls"></a> <a id="session_sqls-class_method"></a>
|
|
88
|
+
Session settings every pooled connection runs as it opens. Sequel runs
|
|
89
|
+
connect_sqls on each new connection, so the whole pool shares them; a SET
|
|
90
|
+
through Database#run reaches only one connection.
|
|
91
|
+
- **`@param`** `config` [Hash] Database configuration (statement_timeout: in ms)
|
|
92
|
+
- **`@return`** [Array<String>] SQL statements
|
|
93
|
+
|
|
94
|
+
### `verify_extensions!()` <a id="method-c-verify_extensions-21"></a> <a id="verify_extensions!-class_method"></a>
|
|
95
|
+
Verify required extensions are available
|
|
96
|
+
- **`@raise`** [RuntimeError] if required extensions are missing
|
|
97
|
+
- **`@return`** [true]
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# Class HTM::Settings <a id="class-HTM-Settings"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Inherits** | Data |
|
|
6
|
+
| **Defined in** | lib/htm/request_options.rb |
|
|
7
|
+
|
|
8
|
+
The keyword arguments HTM.new was given
|
|
9
|
+
|
|
10
|
+
## Attributes
|
|
11
|
+
### `db_cache_size` [R] <a id="attribute-i-db_cache_size"></a> <a id="db_cache_size-instance_method"></a>
|
|
12
|
+
Returns the value of attribute db_cache_size
|
|
13
|
+
- **`@return`** [Object] the current value of db_cache_size
|
|
14
|
+
|
|
15
|
+
### `db_cache_ttl` [R] <a id="attribute-i-db_cache_ttl"></a> <a id="db_cache_ttl-instance_method"></a>
|
|
16
|
+
Returns the value of attribute db_cache_ttl
|
|
17
|
+
- **`@return`** [Object] the current value of db_cache_ttl
|
|
18
|
+
|
|
19
|
+
### `db_config` [R] <a id="attribute-i-db_config"></a> <a id="db_config-instance_method"></a>
|
|
20
|
+
Returns the value of attribute db_config
|
|
21
|
+
- **`@return`** [Object] the current value of db_config
|
|
22
|
+
|
|
23
|
+
### `robot_name` [R] <a id="attribute-i-robot_name"></a> <a id="robot_name-instance_method"></a>
|
|
24
|
+
Returns the value of attribute robot_name
|
|
25
|
+
- **`@return`** [Object] the current value of robot_name
|
|
26
|
+
|
|
27
|
+
### `working_memory_size` [R] <a id="attribute-i-working_memory_size"></a> <a id="working_memory_size-instance_method"></a>
|
|
28
|
+
Returns the value of attribute working_memory_size
|
|
29
|
+
- **`@return`** [Object] the current value of working_memory_size
|
|
30
|
+
|
|
31
|
+
## Public Instance Methods
|
|
32
|
+
### `build_long_term_memory()` <a id="method-i-build_long_term_memory"></a> <a id="build_long_term_memory-instance_method"></a>
|
|
33
|
+
- **`@return`** [HTM::LongTermMemory] Long-term memory built from these settings
|
|
34
|
+
|
|
35
|
+
### `db_config_or_default()` <a id="method-i-db_config_or_default"></a> <a id="db_config_or_default-instance_method"></a>
|
|
36
|
+
- **`@return`** [Hash] The given database config, or HTM::Database.default_config
|
|
37
|
+
|
|
38
|
+
### `robot_name_or_generated()` <a id="method-i-robot_name_or_generated"></a> <a id="robot_name_or_generated-instance_method"></a>
|
|
39
|
+
- **`@return`** [String] The given robot name, or a generated one
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# Module HTM::Sinatra::Helpers <a id="module-HTM-Sinatra-Helpers"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Defined in** | lib/htm/integrations/sinatra.rb |
|
|
6
|
+
|
|
7
|
+
Request helpers mixed into a Sinatra app by register_htm: one HTM instance per
|
|
8
|
+
request, plus remember/recall shortcuts and a JSON helper
|
|
9
|
+
|
|
10
|
+
## Public Instance Methods
|
|
11
|
+
### `htm()` <a id="method-i-htm"></a> <a id="htm-instance_method"></a>
|
|
12
|
+
Get current HTM instance
|
|
13
|
+
- **`@raise`** [RuntimeError] If HTM not initialized (call init_htm first)
|
|
14
|
+
- **`@return`** [HTM] HTM instance for this request
|
|
15
|
+
|
|
16
|
+
### `init_htm(robot_name: 'guest', working_memory_size: 128_000)` <a id="method-i-init_htm"></a> <a id="init_htm-instance_method"></a>
|
|
17
|
+
Initialize HTM instance for current request
|
|
18
|
+
- **`@param`** `robot_name` [String] Robot identifier (typically user/session ID)
|
|
19
|
+
- **`@param`** `working_memory_size` [Integer] Token limit for working memory
|
|
20
|
+
- **`@return`** [HTM] HTM instance for this request
|
|
21
|
+
|
|
22
|
+
### `json(data)` <a id="method-i-json"></a> <a id="json-instance_method"></a>
|
|
23
|
+
JSON response helper
|
|
24
|
+
- **`@param`** `data` [Hash] Data to convert to JSON
|
|
25
|
+
- **`@return`** [String] JSON response
|
|
26
|
+
|
|
27
|
+
### `recall(topic)` <a id="method-i-recall"></a> <a id="recall-instance_method"></a>
|
|
28
|
+
Recall memories (convenience method)
|
|
29
|
+
- **`@param`** `topic` [String] Topic to search for
|
|
30
|
+
- **`@param`** `options` [Hash] Recall options (timeframe, limit, strategy, etc.)
|
|
31
|
+
- **`@return`** [Array<Hash>] Matching memories
|
|
32
|
+
|
|
33
|
+
### `remember(content, tags: [])` <a id="method-i-remember"></a> <a id="remember-instance_method"></a>
|
|
34
|
+
Remember information (convenience method)
|
|
35
|
+
- **`@param`** `content` [String] Content to remember
|
|
36
|
+
- **`@param`** `tags` [Array<String>] Optional tags to assign
|
|
37
|
+
- **`@return`** [Integer] Node ID
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# Class HTM::Sinatra::Middleware <a id="class-HTM-Sinatra-Middleware"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Inherits** | Object |
|
|
6
|
+
| **Defined in** | lib/htm/integrations/sinatra.rb |
|
|
7
|
+
|
|
8
|
+
Rack middleware for HTM connection management
|
|
9
|
+
|
|
10
|
+
Ensures database connections are properly managed across requests. With
|
|
11
|
+
Sequel's fiber-safe connection pooling, this is largely automatic.
|
|
12
|
+
|
|
13
|
+
**@example Use in Sinatra app**
|
|
14
|
+
```ruby
|
|
15
|
+
class MyApp < Sinatra::Base
|
|
16
|
+
use HTM::Sinatra::Middleware
|
|
17
|
+
end
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Public Class Methods
|
|
21
|
+
### `store_config!()` <a id="method-c-store_config-21"></a> <a id="store_config!-class_method"></a>
|
|
22
|
+
Store the connection config at startup (called from register_htm)
|
|
23
|
+
|
|
24
|
+
## Public Instance Methods
|
|
25
|
+
### `call(env)` <a id="method-i-call"></a> <a id="call-instance_method"></a>
|
|
26
|
+
Not documented.
|
|
27
|
+
|
|
28
|
+
### `initialize(app, options = {})` <a id="method-i-initialize"></a> <a id="initialize-instance_method"></a>
|
|
29
|
+
- **`@return`** [Middleware] a new instance of Middleware
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Module HTM::Sinatra <a id="module-HTM-Sinatra"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Defined in** | lib/htm/integrations/sinatra.rb |
|
|
6
|
+
|
|
7
|
+
Sinatra helpers for HTM integration
|
|
8
|
+
|
|
9
|
+
Provides convenient helper methods for using HTM in Sinatra applications.
|
|
10
|
+
|
|
11
|
+
**@example Basic usage**
|
|
12
|
+
```ruby
|
|
13
|
+
require 'htm/integrations/sinatra'
|
|
14
|
+
|
|
15
|
+
class MyApp < Sinatra::Base
|
|
16
|
+
register_htm
|
|
17
|
+
|
|
18
|
+
before do
|
|
19
|
+
init_htm(robot_name: session[:user_id] || 'guest')
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
post '/remember' do
|
|
23
|
+
node_id = remember(params[:content])
|
|
24
|
+
json status: 'ok', node_id: node_id
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
get '/recall' do
|
|
28
|
+
memories = recall(params[:topic], limit: 10)
|
|
29
|
+
json memories: memories
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Public Class Methods
|
|
35
|
+
### `configure!(logger: nil)` <a id="method-c-configure-21"></a> <a id="configure!-class_method"></a>
|
|
36
|
+
Configures HTM for a Sinatra app: the app's logger when one is given, and
|
|
37
|
+
Sidekiq for background jobs when it is loaded (threads otherwise)
|
|
38
|
+
- **`@param`** `logger` [Logger, nil] Logger HTM should write to
|
|
39
|
+
|
|
40
|
+
### `connect!()` <a id="method-c-connect-21"></a> <a id="connect!-class_method"></a>
|
|
41
|
+
Establishes the initial connection (Sequel handles pooling automatically)
|
|
42
|
+
|
|
43
|
+
### `job_backend()` <a id="method-c-job_backend"></a> <a id="job_backend-class_method"></a>
|
|
44
|
+
:sidekiq when Sidekiq is loaded, :thread otherwise
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Module HTM::SqlBuilder::Sparsevec <a id="module-HTM-SqlBuilder-Sparsevec"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Defined in** | lib/htm/sql_builder.rb |
|
|
6
|
+
|
|
7
|
+
Conversion between dense embedding Arrays and pgvector sparsevec literals,
|
|
8
|
+
with the validation that keeps anything but finite numbers out of the SQL
|
|
9
|
+
|
|
10
|
+
## Public Class Methods
|
|
11
|
+
### `dense_length(pairs)` <a id="method-c-dense_length"></a> <a id="dense_length-class_method"></a>
|
|
12
|
+
- **`@param`** `pairs` [Array<Array(Integer, Float)>] 0-based [index, value] pairs
|
|
13
|
+
- **`@return`** [Integer] Length that reaches the highest index (0 when empty)
|
|
14
|
+
|
|
15
|
+
### `densify(pairs, size = dense_length(pairs))` <a id="method-c-densify"></a> <a id="densify-class_method"></a>
|
|
16
|
+
`size` zeros with `pairs` filled in; pairs past `size` are dropped
|
|
17
|
+
- **`@param`** `pairs` [Array<Array(Integer, Float)>] 0-based [index, value] pairs
|
|
18
|
+
- **`@param`** `size` [Integer] Length of the result (default: up to the highest index)
|
|
19
|
+
- **`@return`** [Array<Float>]
|
|
20
|
+
|
|
21
|
+
### `entries(embedding)` <a id="method-c-entries"></a> <a id="entries-class_method"></a>
|
|
22
|
+
The "position:value" entries of a sparsevec literal: 1-based positions, zeros
|
|
23
|
+
dropped
|
|
24
|
+
- **`@param`** `embedding` [Array<Numeric>] Dense embedding of finite numbers
|
|
25
|
+
- **`@return`** [Array<String>] e.g. ["1:0.1", "3:0.3"]
|
|
26
|
+
|
|
27
|
+
### `finite_number?(value)` <a id="method-c-finite_number-3F"></a> <a id="finite_number?-class_method"></a>
|
|
28
|
+
- **`@param`** `value` [Object]
|
|
29
|
+
- **`@return`** [Boolean] true if +value+ is a finite Numeric
|
|
30
|
+
|
|
31
|
+
### `pairs(text)` <a id="method-c-pairs"></a> <a id="pairs-class_method"></a>
|
|
32
|
+
The [index, value] pairs of a sparsevec literal, with 0-based indexes
|
|
33
|
+
- **`@param`** `text` [String] Sparsevec text (e.g., "{1:0.1,3:0.3}/2000")
|
|
34
|
+
- **`@raise`** [ArgumentError] If +text+ is not a sparsevec literal
|
|
35
|
+
- **`@return`** [Array<Array(Integer, Float)>]
|
|
36
|
+
|
|
37
|
+
### `parse_embedding(raw, length: nil)` <a id="method-c-parse_embedding"></a> <a id="parse_embedding-class_method"></a>
|
|
38
|
+
Parse a pgvector sparsevec literal into a dense Array
|
|
39
|
+
- **`@param`** `raw` [String, Array, nil] Sparsevec text (e.g., "{1:0.1,3:0.3}/2000")
|
|
40
|
+
- **`@param`** `length` [Integer, nil] Length of the returned Array; defaults to the
|
|
41
|
+
highest non-zero position
|
|
42
|
+
- **`@return`** [Array<Float>, nil] Dense embedding
|
|
43
|
+
|
|
44
|
+
### `sanitize_embedding(embedding, dimension: MAX_EMBEDDING_DIMENSION)` <a id="method-c-sanitize_embedding"></a> <a id="sanitize_embedding-class_method"></a>
|
|
45
|
+
Convert an embedding to a pgvector sparsevec literal
|
|
46
|
+
|
|
47
|
+
Validates that all values are finite numbers, drops zeros, and writes the
|
|
48
|
+
remaining values with 1-based positions. Only numbers reach the SQL, so the
|
|
49
|
+
result is safe to bind or quote.
|
|
50
|
+
- **`@param`** `embedding` [Array<Numeric>] Dense embedding vector
|
|
51
|
+
- **`@param`** `dimension` [Integer] Declared sparsevec dimension
|
|
52
|
+
- **`@raise`** [ArgumentError] If the embedding is empty, too long, or not numeric
|
|
53
|
+
- **`@return`** [String] Sparsevec literal (e.g., "{1:0.1,3:0.3}/2000")
|
|
54
|
+
|
|
55
|
+
### `validate_embedding_shape!(embedding, dimension)` <a id="method-c-validate_embedding_shape-21"></a> <a id="validate_embedding_shape!-class_method"></a>
|
|
56
|
+
Raise unless `embedding` is a non-empty Array no longer than `dimension`
|
|
57
|
+
- **`@param`** `embedding` [Object] Candidate embedding
|
|
58
|
+
- **`@param`** `dimension` [Integer] Declared sparsevec dimension
|
|
59
|
+
- **`@raise`** [ArgumentError] If the shape is wrong
|
|
60
|
+
|
|
61
|
+
### `validate_embedding_sparsity!(embedding)` <a id="method-c-validate_embedding_sparsity-21"></a> <a id="validate_embedding_sparsity!-class_method"></a>
|
|
62
|
+
Raise if `embedding` has more non-zero values than the HNSW index allows
|
|
63
|
+
- **`@param`** `embedding` [Array<Numeric>] Embedding of finite numbers
|
|
64
|
+
- **`@raise`** [ArgumentError] If there are more than MAX_SPARSE_NONZERO non-zero values
|
|
65
|
+
|
|
66
|
+
### `validate_embedding_values!(embedding)` <a id="method-c-validate_embedding_values-21"></a> <a id="validate_embedding_values!-class_method"></a>
|
|
67
|
+
Raise unless every value in `embedding` is a finite number
|
|
68
|
+
- **`@param`** `embedding` [Array] Candidate embedding
|
|
69
|
+
- **`@raise`** [ArgumentError] Naming up to five offending indexes
|
|
@@ -1,108 +1,95 @@
|
|
|
1
|
-
# Class
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# Class HTM::SqlBuilder <a id="class-HTM-SqlBuilder"></a>
|
|
2
|
+
|
|
3
|
+
| | |
|
|
4
|
+
| --- | --- |
|
|
5
|
+
| **Inherits** | Object |
|
|
6
|
+
| **Extended by** | SingleForwardable |
|
|
7
|
+
| **Defined in** | lib/htm/sql_builder.rb |
|
|
4
8
|
|
|
5
9
|
SQL building utilities for constructing safe, parameterized queries
|
|
6
10
|
|
|
7
11
|
Provides class methods for building SQL conditions for:
|
|
8
12
|
* Timeframe filtering (single range or multiple ranges)
|
|
9
13
|
* Metadata filtering (JSONB containment)
|
|
10
|
-
* Embedding
|
|
14
|
+
* Embedding conversion to pgvector sparsevec literals (SQL injection
|
|
15
|
+
prevention)
|
|
11
16
|
* LIKE pattern sanitization (wildcard injection prevention)
|
|
12
17
|
|
|
13
18
|
All methods use proper escaping and parameterization to prevent SQL injection.
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
**`@example`**
|
|
20
|
+
**@example Build a timeframe condition**
|
|
17
21
|
```ruby
|
|
18
22
|
HTM::SqlBuilder.timeframe_condition(1.week.ago..Time.now)
|
|
19
23
|
# => "(created_at BETWEEN '2024-01-01' AND '2024-01-08')"
|
|
20
24
|
```
|
|
21
|
-
|
|
25
|
+
|
|
26
|
+
**@example Build a metadata condition**
|
|
22
27
|
```ruby
|
|
23
28
|
HTM::SqlBuilder.metadata_condition({ priority: "high" })
|
|
24
29
|
# => "(metadata @> '{\"priority\":\"high\"}'::jsonb)"
|
|
25
30
|
```
|
|
26
|
-
|
|
31
|
+
|
|
32
|
+
**@example Sanitize an embedding**
|
|
27
33
|
```ruby
|
|
28
34
|
HTM::SqlBuilder.sanitize_embedding([0.1, 0.2, 0.3])
|
|
29
|
-
# => "
|
|
35
|
+
# => "{1:0.1,2:0.2,3:0.3}/2000"
|
|
30
36
|
```
|
|
31
|
-
|
|
37
|
+
|
|
38
|
+
**@example Sanitize a LIKE pattern**
|
|
32
39
|
```ruby
|
|
33
40
|
HTM::SqlBuilder.sanitize_like_pattern("test%pattern")
|
|
34
41
|
# => "test\\%pattern"
|
|
35
42
|
```
|
|
36
|
-
# Class Methods
|
|
37
|
-
## apply_metadata(scope , metadata , column: "metadata") {: #method-c-apply_metadata }
|
|
38
|
-
Apply metadata filter to ActiveRecord scope
|
|
39
|
-
**`@param`** [ActiveRecord::Relation] Base scope
|
|
40
|
-
|
|
41
|
-
**`@param`** [Hash] Metadata to filter by
|
|
42
|
-
|
|
43
|
-
**`@param`** [String] Column name (default: "metadata")
|
|
44
|
-
|
|
45
|
-
**`@return`** [ActiveRecord::Relation] Scoped query
|
|
46
43
|
|
|
47
|
-
##
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
44
|
+
## Constants
|
|
45
|
+
### `MAX_EMBEDDING_DIMENSION` <a id="constant-MAX_EMBEDDING_DIMENSION"></a> <a id="MAX_EMBEDDING_DIMENSION-constant"></a>
|
|
46
|
+
Declared dimension of the nodes.embedding sparsevec column
|
|
47
|
+
|
|
48
|
+
### `MAX_SPARSE_NONZERO` <a id="constant-MAX_SPARSE_NONZERO"></a> <a id="MAX_SPARSE_NONZERO-constant"></a>
|
|
49
|
+
pgvector's HNSW index on sparsevec accepts at most this many non-zero elements
|
|
50
|
+
|
|
51
|
+
## Public Class Methods
|
|
52
|
+
### `apply_metadata(scope, metadata, column: "metadata")` <a id="method-c-apply_metadata"></a> <a id="apply_metadata-class_method"></a>
|
|
53
|
+
Apply metadata filter to Sequel dataset
|
|
54
|
+
- **`@param`** `scope` [Sequel::Dataset] Base dataset
|
|
55
|
+
- **`@param`** `metadata` [Hash] Metadata to filter by
|
|
56
|
+
- **`@param`** `column` [String] Column name (default: "metadata")
|
|
57
|
+
- **`@return`** [Sequel::Dataset] Filtered dataset
|
|
58
|
+
|
|
59
|
+
### `apply_timeframe(scope, timeframe, column: :created_at)` <a id="method-c-apply_timeframe"></a> <a id="apply_timeframe-class_method"></a>
|
|
60
|
+
Apply timeframe filter to Sequel dataset
|
|
61
|
+
- **`@param`** `scope` [Sequel::Dataset] Base dataset
|
|
62
|
+
- **`@param`** `timeframe` [nil, Range, Array<Range>] Time range(s)
|
|
63
|
+
- **`@param`** `column` [Symbol] Column name (default: :created_at)
|
|
64
|
+
- **`@return`** [Sequel::Dataset] Filtered dataset
|
|
65
|
+
|
|
66
|
+
### `between_condition(column, range)` <a id="method-c-between_condition"></a> <a id="between_condition-class_method"></a>
|
|
67
|
+
- **`@param`** `column` [String] Column name
|
|
68
|
+
- **`@param`** `range` [Range<Time>] Time range
|
|
69
|
+
- **`@return`** [String] "(column BETWEEN 'begin' AND 'end')" with quoted ISO 8601 times
|
|
70
|
+
|
|
71
|
+
### `metadata_condition(metadata, table_alias: nil, column: "metadata")` <a id="method-c-metadata_condition"></a> <a id="metadata_condition-class_method"></a>
|
|
58
72
|
Build SQL condition for metadata filtering (JSONB containment)
|
|
59
|
-
**`@param`** [Hash] Metadata to filter by
|
|
60
|
-
|
|
61
|
-
**`@param`** [String
|
|
62
|
-
|
|
63
|
-
**`@param`** [String] Column name (default: "metadata")
|
|
64
|
-
|
|
65
|
-
**`@return`** [String, nil] SQL condition or nil for no filter
|
|
73
|
+
- **`@param`** `metadata` [Hash] Metadata to filter by
|
|
74
|
+
- **`@param`** `table_alias` [String, nil] Table alias (default: none)
|
|
75
|
+
- **`@param`** `column` [String] Column name (default: "metadata")
|
|
76
|
+
- **`@return`** [String, nil] SQL condition or nil for no filter
|
|
66
77
|
|
|
67
|
-
|
|
68
|
-
Pad embedding to target dimension
|
|
69
|
-
|
|
70
|
-
Pads embedding with zeros to reach the target dimension for pgvector
|
|
71
|
-
compatibility.
|
|
72
|
-
**`@param`** [Array<Numeric>] Embedding vector
|
|
73
|
-
|
|
74
|
-
**`@param`** [Integer] Target dimension (default: MAX_EMBEDDING_DIMENSION)
|
|
75
|
-
|
|
76
|
-
**`@return`** [Array<Numeric>] Padded embedding
|
|
77
|
-
|
|
78
|
-
## sanitize_embedding(embedding ) {: #method-c-sanitize_embedding }
|
|
79
|
-
Sanitize embedding for SQL use
|
|
80
|
-
|
|
81
|
-
Validates that all values are numeric and converts to safe PostgreSQL vector
|
|
82
|
-
format. This prevents SQL injection by ensuring only valid numeric values are
|
|
83
|
-
included.
|
|
84
|
-
**`@param`** [Array<Numeric>] Embedding vector
|
|
85
|
-
|
|
86
|
-
**`@raise`** [ArgumentError] If embedding contains non-numeric values
|
|
87
|
-
|
|
88
|
-
**`@return`** [String] Sanitized vector string for PostgreSQL (e.g., "[0.1,0.2,0.3]")
|
|
89
|
-
|
|
90
|
-
## sanitize_like_pattern(pattern ) {: #method-c-sanitize_like_pattern }
|
|
78
|
+
### `sanitize_like_pattern(pattern)` <a id="method-c-sanitize_like_pattern"></a> <a id="sanitize_like_pattern-class_method"></a>
|
|
91
79
|
Sanitize a string for use in SQL LIKE patterns
|
|
92
80
|
|
|
93
81
|
Escapes SQL LIKE wildcards (% and _) to prevent pattern injection.
|
|
94
|
-
**`@param`** [String] Pattern to sanitize
|
|
95
|
-
|
|
96
|
-
**`@return`** [String] Sanitized pattern safe for LIKE queries
|
|
82
|
+
- **`@param`** `pattern` [String] Pattern to sanitize
|
|
83
|
+
- **`@return`** [String] Sanitized pattern safe for LIKE queries
|
|
97
84
|
|
|
98
|
-
|
|
85
|
+
### `timeframe_condition(timeframe, table_alias: nil, column: "created_at")` <a id="method-c-timeframe_condition"></a> <a id="timeframe_condition-class_method"></a>
|
|
99
86
|
Build SQL condition for timeframe filtering
|
|
100
|
-
**`@param`** [nil, Range, Array<Range>] Time range(s)
|
|
101
|
-
|
|
102
|
-
**`@param`** [String
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
87
|
+
- **`@param`** `timeframe` [nil, Range, Array<Range>] Time range(s)
|
|
88
|
+
- **`@param`** `table_alias` [String, nil] Table alias (default: none)
|
|
89
|
+
- **`@param`** `column` [String] Column name (default: "created_at")
|
|
90
|
+
- **`@return`** [String, nil] SQL condition or nil for no filter
|
|
91
|
+
|
|
92
|
+
### `vector_search_sql(filters = [])` <a id="method-c-vector_search_sql"></a> <a id="vector_search_sql-class_method"></a>
|
|
93
|
+
SQL for a nearest-neighbor query; binds the embedding twice, then the limit
|
|
94
|
+
- **`@param`** `filters` [Array<String>] extra conditions to AND into the WHERE clause
|
|
95
|
+
- **`@return`** [String]
|