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,454 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class HTM
|
|
4
|
+
module Admin
|
|
5
|
+
# The `htm db ...` commands that are more than one HTM::Database call
|
|
6
|
+
module DatabaseCommands
|
|
7
|
+
DROP_PROMPT = "Are you sure you want to drop all tables? This cannot be undone! (yes/no): "
|
|
8
|
+
|
|
9
|
+
module_function
|
|
10
|
+
|
|
11
|
+
# Open a PG connection from an HTM database config
|
|
12
|
+
#
|
|
13
|
+
# @param config [Hash] HTM::SequelConfig.load_database_config
|
|
14
|
+
# @param dbname [String] Database to connect to
|
|
15
|
+
# @return [PG::Connection]
|
|
16
|
+
#
|
|
17
|
+
def pg_connect(config, dbname: config[:database])
|
|
18
|
+
require 'pg'
|
|
19
|
+
PG.connect(host: config[:host], port: config[:port], dbname:,
|
|
20
|
+
user: config[:username], password: config[:password])
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Create the configured database (with pgvector and pg_trgm) unless it exists
|
|
24
|
+
#
|
|
25
|
+
# @return [Symbol] :created or :exists
|
|
26
|
+
# @raise [HTM::Admin::Error] when PostgreSQL refuses
|
|
27
|
+
#
|
|
28
|
+
def create(config = HTM::SequelConfig.load_database_config, out: $stdout)
|
|
29
|
+
name = config[:database]
|
|
30
|
+
out.puts "Creating database: #{name} (#{HTM.env})"
|
|
31
|
+
unless create_database(config)
|
|
32
|
+
out.puts "✓ Database already exists: #{name}"
|
|
33
|
+
return :exists
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
out.puts "✓ Database created: #{name}"
|
|
37
|
+
enable_extensions(config)
|
|
38
|
+
out.puts "✓ Extensions enabled (pgvector, pg_trgm)"
|
|
39
|
+
:created
|
|
40
|
+
rescue PG::Error => e
|
|
41
|
+
raise Admin::Error, "✗ Error: #{e.message}"
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Create the configured database unless the server already has it
|
|
45
|
+
#
|
|
46
|
+
# @param config [Hash] HTM::SequelConfig.load_database_config
|
|
47
|
+
# @return [Boolean] true when created, false when it already existed
|
|
48
|
+
#
|
|
49
|
+
def create_database(config)
|
|
50
|
+
name = config[:database]
|
|
51
|
+
admin = pg_connect(config, dbname: 'postgres')
|
|
52
|
+
return false if database_exists?(admin, name)
|
|
53
|
+
|
|
54
|
+
admin.exec("CREATE DATABASE #{PG::Connection.quote_ident(name)}")
|
|
55
|
+
true
|
|
56
|
+
ensure
|
|
57
|
+
admin&.close
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# @return [Boolean] whether the server behind +conn+ has database +name+
|
|
61
|
+
def database_exists?(conn, name)
|
|
62
|
+
conn.exec_params("SELECT 1 FROM pg_database WHERE datname = $1", [name]).ntuples.positive?
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Enable the extensions HTM needs in the configured database
|
|
66
|
+
def enable_extensions(config, extensions: %w[vector pg_trgm])
|
|
67
|
+
conn = pg_connect(config)
|
|
68
|
+
extensions.each { conn.exec("CREATE EXTENSION IF NOT EXISTS #{it}") }
|
|
69
|
+
ensure
|
|
70
|
+
conn&.close
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Connect to the configured database and report pgvector
|
|
74
|
+
#
|
|
75
|
+
# @return [true]
|
|
76
|
+
# @raise [HTM::Admin::Error] when the connection fails
|
|
77
|
+
#
|
|
78
|
+
def verify(config = HTM::SequelConfig.load_database_config, out: $stdout)
|
|
79
|
+
Admin.print_counts("Verifying HTM database connection (#{HTM.env})...", {
|
|
80
|
+
'Host' => config[:host],
|
|
81
|
+
'Port' => config[:port],
|
|
82
|
+
'Database' => config[:database],
|
|
83
|
+
'User' => config[:username]
|
|
84
|
+
}, out:)
|
|
85
|
+
|
|
86
|
+
conn = pg_connect(config)
|
|
87
|
+
version = pgvector_version(conn)
|
|
88
|
+
conn.close
|
|
89
|
+
out.puts version ? " ✓ pgvector version: #{version}" : " ⚠ Warning: pgvector extension not found"
|
|
90
|
+
out.puts "✓ Connection successful!"
|
|
91
|
+
true
|
|
92
|
+
rescue PG::Error => e
|
|
93
|
+
raise Admin::Error, "✗ Connection failed: #{e.message}"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
# @return [String, nil] the installed pgvector version, nil when absent
|
|
97
|
+
def pgvector_version(conn)
|
|
98
|
+
conn.exec("SELECT extversion FROM pg_extension WHERE extname='vector'").first&.fetch('extversion')
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# @return [Array<String>] the psql command line for the configured database
|
|
102
|
+
def console_command(config = HTM::SequelConfig.load_database_config)
|
|
103
|
+
["psql", "-h", config[:host].to_s, "-p", config[:port].to_s, "-U", config[:username].to_s, "-d", config[:database].to_s]
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# Drop all HTM tables, asking first unless +confirm+
|
|
107
|
+
#
|
|
108
|
+
# @return [Symbol, nil] :dropped, nil when cancelled
|
|
109
|
+
#
|
|
110
|
+
def drop(confirm: nil) = Console.new(assume_yes: confirm).drop
|
|
111
|
+
|
|
112
|
+
# Drop all HTM tables and set the schema up again, asking first unless +confirm+
|
|
113
|
+
#
|
|
114
|
+
# @return [Symbol, nil] :reset, nil when cancelled
|
|
115
|
+
#
|
|
116
|
+
def reset(confirm: nil) = Console.new(assume_yes: confirm).reset
|
|
117
|
+
|
|
118
|
+
# Report what would be purged, ask, then purge (see Console#purge_all)
|
|
119
|
+
def purge_all = Console.new.purge_all
|
|
120
|
+
|
|
121
|
+
# Clear every embedding and regenerate them all, after confirmation (see Console#rebuild_embeddings)
|
|
122
|
+
def rebuild_embeddings = Console.new.rebuild_embeddings
|
|
123
|
+
|
|
124
|
+
# Delete every proposition node and extract them all again, after confirmation
|
|
125
|
+
# (see Console#rebuild_propositions)
|
|
126
|
+
def rebuild_propositions = Console.new.rebuild_propositions
|
|
127
|
+
|
|
128
|
+
# Row counts per HTM table, with a note for nodes
|
|
129
|
+
#
|
|
130
|
+
# @return [Array<Array(String, Integer, String)>] [table, count, note]
|
|
131
|
+
#
|
|
132
|
+
def table_counts
|
|
133
|
+
nodes = HTM::Models::Node
|
|
134
|
+
active = nodes.count
|
|
135
|
+
[
|
|
136
|
+
['robots', HTM::Models::Robot.count, ''],
|
|
137
|
+
['nodes', active,
|
|
138
|
+
" (active: #{active}, deleted: #{nodes.deleted.count}, " \
|
|
139
|
+
"with embeddings: #{nodes.exclude(embedding: nil).count})"],
|
|
140
|
+
['tags', HTM::Models::Tag.count, ''],
|
|
141
|
+
['nodes_tags', HTM::Models::NodeTag.count, ''],
|
|
142
|
+
['file_sources', HTM::Models::FileSource.count, '']
|
|
143
|
+
]
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# @return [Array<Array(String, Integer)>] robots with the most active nodes
|
|
147
|
+
def top_robots(limit = 5)
|
|
148
|
+
HTM::Models::RobotNode
|
|
149
|
+
.join(:nodes, id: :node_id)
|
|
150
|
+
.where(Sequel[:nodes][:deleted_at] => nil)
|
|
151
|
+
.group_and_count(:robot_id)
|
|
152
|
+
.all
|
|
153
|
+
.map { [robot_label(it[:robot_id]), it[:count]] }
|
|
154
|
+
.sort_by { -it.last }
|
|
155
|
+
.first(limit)
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
# @return [String] the name of robot +id+, or "Unknown (id)" when it is gone
|
|
159
|
+
def robot_label(id) = HTM::Models::Robot[id]&.name || "Unknown (#{id})"
|
|
160
|
+
|
|
161
|
+
# @return [Array<Array(String, Integer)>] root tag names with the most tags under them
|
|
162
|
+
def top_root_tags(limit = 5)
|
|
163
|
+
root = Sequel.lit("split_part(name, ':', 1)")
|
|
164
|
+
HTM.db[:tags]
|
|
165
|
+
.select(Sequel.as(root, :root), Sequel.function(:count, Sequel.lit('*')).as(:cnt))
|
|
166
|
+
.group(root)
|
|
167
|
+
.order(Sequel.desc(:cnt))
|
|
168
|
+
.limit(limit)
|
|
169
|
+
.all
|
|
170
|
+
.map { [it[:root], it[:cnt]] }
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Print record counts for every HTM table, top robots and top root tags
|
|
174
|
+
def stats(out: $stdout)
|
|
175
|
+
Admin.connect!
|
|
176
|
+
out.puts "\nHTM Database Statistics"
|
|
177
|
+
out.puts "=" * 50
|
|
178
|
+
print_table_counts(table_counts, out)
|
|
179
|
+
out.puts "\nAdditional Statistics:"
|
|
180
|
+
print_ranking("Top robots by node count:", top_robots, out)
|
|
181
|
+
print_ranking("Top root tag categories:", top_root_tags, out)
|
|
182
|
+
out.puts
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def print_table_counts(rows, out)
|
|
186
|
+
width = rows.map { it.first.length }.max
|
|
187
|
+
rows.each { |name, count, note| out.puts " #{count_line(name, count, width)}#{note}" }
|
|
188
|
+
out.puts "-" * 50
|
|
189
|
+
out.puts " #{count_line('Total', rows.sum { it[1] }, width)}"
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
# @return [String] +label+ padded to +width+ and +count+ right-aligned in 8 columns
|
|
193
|
+
def count_line(label, count, width, gap: 2) = "#{label.to_s.ljust(width)}#{' ' * gap}#{count.to_s.rjust(8)}"
|
|
194
|
+
|
|
195
|
+
def print_ranking(title, rows, out)
|
|
196
|
+
return if rows.empty?
|
|
197
|
+
|
|
198
|
+
out.puts " #{title}"
|
|
199
|
+
rows.each { |name, count| out.puts " #{name}: #{count}" }
|
|
200
|
+
end
|
|
201
|
+
|
|
202
|
+
# Proposition nodes (active or soft-deleted) with no derived_from link:
|
|
203
|
+
# their source node was purged, which cascades away the link
|
|
204
|
+
#
|
|
205
|
+
# @return [Sequel::Dataset]
|
|
206
|
+
#
|
|
207
|
+
def orphaned_propositions
|
|
208
|
+
linked = HTM::Models::NodeLink.of_kind(:derived_from).where(from_node_id: Sequel[:nodes][:id]).select(1)
|
|
209
|
+
HTM::Models::Node.with_deleted.propositions.exclude(linked.exists)
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
# @return [Sequel::Dataset] rows of +model+ (node_tags, robot_nodes) pointing to missing nodes
|
|
213
|
+
def orphaned_links(model)
|
|
214
|
+
rows = model.with_deleted
|
|
215
|
+
ids = rows.left_join(:nodes, id: :node_id).where(Sequel[:nodes][:id] => nil).select_map(Sequel[model.table_name][:id])
|
|
216
|
+
rows.where(id: ids)
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
# @return [Sequel::Dataset] robots with no memory nodes
|
|
220
|
+
def orphaned_robots
|
|
221
|
+
linked = HTM::Models::RobotNode.where(Sequel[:robot_nodes][:robot_id] => Sequel[:robots][:id]).select(1)
|
|
222
|
+
HTM::Models::Robot.where(Sequel.~(Sequel.exists(linked)))
|
|
223
|
+
end
|
|
224
|
+
|
|
225
|
+
# What purge_all would delete
|
|
226
|
+
#
|
|
227
|
+
# @return [Hash{Symbol => Integer}]
|
|
228
|
+
#
|
|
229
|
+
def purge_counts
|
|
230
|
+
{
|
|
231
|
+
deleted_nodes: HTM::Models::Node.deleted.count,
|
|
232
|
+
deleted_node_tags: HTM::Models::NodeTag.deleted.count,
|
|
233
|
+
deleted_robot_nodes: HTM::Models::RobotNode.deleted.count,
|
|
234
|
+
orphaned_propositions: orphaned_propositions.count,
|
|
235
|
+
orphaned_node_tags: orphaned_links(HTM::Models::NodeTag).count,
|
|
236
|
+
orphaned_robot_nodes: orphaned_links(HTM::Models::RobotNode).count,
|
|
237
|
+
orphaned_robots: orphaned_robots.count
|
|
238
|
+
}
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# Permanently delete soft-deleted and orphaned records, children first
|
|
242
|
+
#
|
|
243
|
+
# @return [Hash{Symbol => Integer}] rows deleted per kind
|
|
244
|
+
#
|
|
245
|
+
def purge!
|
|
246
|
+
purged = {}
|
|
247
|
+
# Orphaned propositions first: deleting them orphans their join rows
|
|
248
|
+
purged[:orphaned_propositions] = orphaned_propositions.delete
|
|
249
|
+
purged[:orphaned_node_tags] = orphaned_links(HTM::Models::NodeTag).delete
|
|
250
|
+
purged[:deleted_node_tags] = HTM::Models::NodeTag.deleted.delete
|
|
251
|
+
purged[:orphaned_robot_nodes] = orphaned_links(HTM::Models::RobotNode).delete
|
|
252
|
+
purged[:deleted_robot_nodes] = HTM::Models::RobotNode.deleted.delete
|
|
253
|
+
purged[:deleted_nodes] = HTM::Models::Node.deleted.delete
|
|
254
|
+
purged[:orphaned_robots] = orphaned_robots.delete
|
|
255
|
+
purged
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
# Labels, purge_counts keys and notes of the soft-deleted rows purge_all reports
|
|
259
|
+
SOFT_DELETED_ROWS = [
|
|
260
|
+
['nodes', :deleted_nodes, ''],
|
|
261
|
+
['node_tags', :deleted_node_tags, ''],
|
|
262
|
+
['robot_nodes', :deleted_robot_nodes, '']
|
|
263
|
+
].freeze
|
|
264
|
+
|
|
265
|
+
# Labels, purge_counts keys and notes of the orphaned rows purge_all reports
|
|
266
|
+
ORPHANED_ROWS = [
|
|
267
|
+
['propositions', :orphaned_propositions, ' (source node no longer exists)'],
|
|
268
|
+
['node_tags', :orphaned_node_tags, ' (pointing to missing nodes)'],
|
|
269
|
+
['robot_nodes', :orphaned_robot_nodes, ' (pointing to missing nodes)'],
|
|
270
|
+
['robots', :orphaned_robots, ' (no associated memory nodes)']
|
|
271
|
+
].freeze
|
|
272
|
+
|
|
273
|
+
def print_purge_counts(counts, out)
|
|
274
|
+
out.puts "\nSoft-deleted records by table:"
|
|
275
|
+
print_purge_rows(SOFT_DELETED_ROWS, counts, out)
|
|
276
|
+
out.puts "\nOrphaned records:"
|
|
277
|
+
print_purge_rows(ORPHANED_ROWS, counts, out)
|
|
278
|
+
out.puts " #{'-' * 40}"
|
|
279
|
+
out.puts " #{count_line('Total', counts.values.sum, 20, gap: 1)}"
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
# Print one line per [label, key, note] of +specs+ with its count from +counts+
|
|
283
|
+
def print_purge_rows(specs, counts, out)
|
|
284
|
+
specs.each { |label, key, note| out.puts " #{count_line(label, counts[key], 20, gap: 1)}#{note}" }
|
|
285
|
+
end
|
|
286
|
+
|
|
287
|
+
def print_purged(purged, out)
|
|
288
|
+
out.puts "\nPurge complete!"
|
|
289
|
+
purged.each { |kind, count| out.puts " #{"#{kind.to_s.tr('_', ' ').capitalize} purged:".ljust(30)} #{count}" }
|
|
290
|
+
out.puts " #{'-' * 40}"
|
|
291
|
+
out.puts " #{'Total records purged:'.ljust(30)} #{purged.values.sum}"
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# Extract propositions for every node of +sources+ under a progress bar
|
|
295
|
+
#
|
|
296
|
+
# @return [Hash] { ok:, failed:, created: }
|
|
297
|
+
#
|
|
298
|
+
def extract_all_propositions(sources, robot, out)
|
|
299
|
+
created = 0
|
|
300
|
+
counts = Admin.each_with_progress(sources, 'Extracting', out:) do |node, bar|
|
|
301
|
+
created += Admin.extract_propositions!(node, robot, warn: bar.method(:log))
|
|
302
|
+
end
|
|
303
|
+
counts.merge(created:)
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
# The `htm db ...` commands that ask before they destroy anything
|
|
307
|
+
#
|
|
308
|
+
# @example
|
|
309
|
+
# HTM::Admin::DatabaseCommands::Console.new(input: StringIO.new("yes\n")).purge_all
|
|
310
|
+
#
|
|
311
|
+
class Console < Admin::Console
|
|
312
|
+
LONG_RUNNING = "This operation may take a long time depending on your LLM provider."
|
|
313
|
+
|
|
314
|
+
# Drop all HTM tables, asking first
|
|
315
|
+
#
|
|
316
|
+
# @return [Symbol, nil] :dropped, nil when cancelled
|
|
317
|
+
#
|
|
318
|
+
def drop
|
|
319
|
+
return cancelled unless confirmed?(DROP_PROMPT)
|
|
320
|
+
|
|
321
|
+
HTM::Database.drop
|
|
322
|
+
:dropped
|
|
323
|
+
end
|
|
324
|
+
|
|
325
|
+
# Drop all HTM tables and set the schema up again, asking first
|
|
326
|
+
#
|
|
327
|
+
# @return [Symbol, nil] :reset, nil when cancelled
|
|
328
|
+
#
|
|
329
|
+
def reset
|
|
330
|
+
return cancelled unless confirmed?(DROP_PROMPT)
|
|
331
|
+
|
|
332
|
+
HTM::Database.drop
|
|
333
|
+
HTM::Database.setup(dump_schema: true)
|
|
334
|
+
:reset
|
|
335
|
+
end
|
|
336
|
+
|
|
337
|
+
# Report what would be purged, ask, then purge
|
|
338
|
+
#
|
|
339
|
+
# @return [Hash, nil] rows deleted per kind, nil when nothing was purged
|
|
340
|
+
#
|
|
341
|
+
def purge_all
|
|
342
|
+
Admin.connect!
|
|
343
|
+
heading("HTM Purge All Soft-Deleted Records", 60)
|
|
344
|
+
counts = DatabaseCommands.purge_counts
|
|
345
|
+
DatabaseCommands.print_purge_counts(counts, out)
|
|
346
|
+
return say("\nNo records to purge.") if counts.values.sum.zero?
|
|
347
|
+
|
|
348
|
+
out.puts "\nWARNING: This permanently deletes records and cannot be undone!"
|
|
349
|
+
return cancelled unless confirmed?("Type 'yes' to continue with hard delete: ")
|
|
350
|
+
|
|
351
|
+
purge
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
# Clear every embedding and regenerate them all, after confirmation
|
|
355
|
+
#
|
|
356
|
+
# @return [Hash, nil] { ok:, failed: } or nil when aborted
|
|
357
|
+
#
|
|
358
|
+
def rebuild_embeddings
|
|
359
|
+
Admin.connect!
|
|
360
|
+
total = HTM::Models::Node.count
|
|
361
|
+
embedded = HTM::Models::Node.exclude(embedding: nil)
|
|
362
|
+
announce_embeddings_rebuild(total, embedded.count)
|
|
363
|
+
return aborted unless proceed?
|
|
364
|
+
|
|
365
|
+
out.puts "\nClearing existing embeddings..."
|
|
366
|
+
out.puts " Cleared #{embedded.update(embedding: nil)} embeddings"
|
|
367
|
+
regenerate_embeddings(total, embedded)
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
# Delete every proposition node and extract them all again, after confirmation
|
|
371
|
+
#
|
|
372
|
+
# @return [Hash, nil] { ok:, failed:, created: } or nil when aborted
|
|
373
|
+
#
|
|
374
|
+
def rebuild_propositions
|
|
375
|
+
Admin.connect!
|
|
376
|
+
sources = HTM::Models::Node.non_propositions
|
|
377
|
+
propositions = HTM::Models::Node.propositions
|
|
378
|
+
source_count = sources.count
|
|
379
|
+
existing = propositions.count
|
|
380
|
+
announce_propositions_rebuild(source_count, existing)
|
|
381
|
+
return aborted unless proceed?
|
|
382
|
+
|
|
383
|
+
delete_propositions(propositions, existing)
|
|
384
|
+
regenerate_propositions(sources, source_count, propositions)
|
|
385
|
+
end
|
|
386
|
+
|
|
387
|
+
private
|
|
388
|
+
|
|
389
|
+
def purge
|
|
390
|
+
out.puts "\nPurging records..."
|
|
391
|
+
purged = DatabaseCommands.purge!
|
|
392
|
+
DatabaseCommands.print_purged(purged, out)
|
|
393
|
+
purged
|
|
394
|
+
end
|
|
395
|
+
|
|
396
|
+
def announce_embeddings_rebuild(total, with_embeddings)
|
|
397
|
+
heading("HTM Embeddings Rebuild")
|
|
398
|
+
print_counts("Current state:", {
|
|
399
|
+
'Total active nodes' => total,
|
|
400
|
+
'With embeddings' => with_embeddings,
|
|
401
|
+
'Without embeddings' => total - with_embeddings
|
|
402
|
+
})
|
|
403
|
+
out.puts "\nThis will regenerate embeddings for ALL #{total} nodes."
|
|
404
|
+
out.puts LONG_RUNNING
|
|
405
|
+
end
|
|
406
|
+
|
|
407
|
+
# @param embedded [Sequel::Dataset] the nodes with an embedding
|
|
408
|
+
# @return [Hash] { ok:, failed: }
|
|
409
|
+
def regenerate_embeddings(total, embedded)
|
|
410
|
+
out.puts "\nGenerating embeddings for #{total} nodes..."
|
|
411
|
+
counts = each_with_progress(HTM::Models::Node.dataset, 'Embedding') { |node, _bar| Admin.embed!(node) }
|
|
412
|
+
print_counts("\nRebuild complete!", {
|
|
413
|
+
'Nodes processed' => total,
|
|
414
|
+
'Successful' => counts[:ok],
|
|
415
|
+
'Errors' => counts[:failed],
|
|
416
|
+
'Nodes with embeddings' => embedded.count
|
|
417
|
+
})
|
|
418
|
+
counts
|
|
419
|
+
end
|
|
420
|
+
|
|
421
|
+
def announce_propositions_rebuild(source_count, existing)
|
|
422
|
+
heading("HTM Propositions Rebuild")
|
|
423
|
+
print_counts("Current state:", {
|
|
424
|
+
'Source nodes (non-propositions)' => source_count,
|
|
425
|
+
'Existing proposition nodes' => existing
|
|
426
|
+
})
|
|
427
|
+
out.puts "\nThis will extract propositions from ALL #{source_count} source nodes."
|
|
428
|
+
out.puts "Existing proposition nodes will be deleted and regenerated."
|
|
429
|
+
out.puts LONG_RUNNING
|
|
430
|
+
end
|
|
431
|
+
|
|
432
|
+
def delete_propositions(propositions, existing)
|
|
433
|
+
return unless existing.positive?
|
|
434
|
+
|
|
435
|
+
out.puts "\nDeleting #{existing} existing proposition nodes..."
|
|
436
|
+
out.puts " Deleted #{propositions.delete} proposition nodes"
|
|
437
|
+
end
|
|
438
|
+
|
|
439
|
+
# @return [Hash] { ok:, failed:, created: }
|
|
440
|
+
def regenerate_propositions(sources, source_count, propositions)
|
|
441
|
+
out.puts "\nExtracting propositions from #{source_count} nodes..."
|
|
442
|
+
counts = DatabaseCommands.extract_all_propositions(sources, Admin.proposition_robot('proposition_rebuilder'), out)
|
|
443
|
+
print_counts("\nRebuild complete!", {
|
|
444
|
+
'Source nodes processed' => counts[:ok],
|
|
445
|
+
'Propositions created' => counts[:created],
|
|
446
|
+
'Errors' => counts[:failed],
|
|
447
|
+
'Total proposition nodes' => propositions.count
|
|
448
|
+
})
|
|
449
|
+
counts
|
|
450
|
+
end
|
|
451
|
+
end
|
|
452
|
+
end
|
|
453
|
+
end
|
|
454
|
+
end
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
class HTM
|
|
4
|
+
module Admin
|
|
5
|
+
# The `htm enrich ...` commands: catch up on, inspect and redo the
|
|
6
|
+
# work HTM's background jobs do for each node (embeddings, tags,
|
|
7
|
+
# propositions).
|
|
8
|
+
module EnrichCommands
|
|
9
|
+
# Nodes older than this without an embedding or tags count as failed
|
|
10
|
+
STALE_AFTER = 3600
|
|
11
|
+
|
|
12
|
+
# Existing tags offered to the tag extractor as ontology context
|
|
13
|
+
ONTOLOGY_SIZE = 100
|
|
14
|
+
|
|
15
|
+
module_function
|
|
16
|
+
|
|
17
|
+
# @return [Sequel::Dataset] active nodes with no embedding
|
|
18
|
+
def nodes_without_embeddings = HTM::Models::Node.where(embedding: nil)
|
|
19
|
+
|
|
20
|
+
# @return [Sequel::Dataset] active nodes with no active tag link
|
|
21
|
+
def nodes_without_tags
|
|
22
|
+
HTM::Models::Node.where(Sequel.~(HTM::Models::NodeTag.where(Sequel[:node_tags][:node_id] => Sequel[:nodes][:id]).select(1).exists))
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# @return [Array<Integer>] ids of nodes that already have proposition nodes
|
|
26
|
+
def proposition_source_ids = HTM::Models::Node.proposition_source_ids
|
|
27
|
+
|
|
28
|
+
# @return [Sequel::Dataset] non-proposition nodes no proposition points back to
|
|
29
|
+
def nodes_without_propositions(processed_ids = proposition_source_ids)
|
|
30
|
+
HTM::Models::Node.non_propositions.exclude(id: processed_ids)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# @return [Hash{Integer => Integer}] tag count per depth (colons in the name), by depth
|
|
34
|
+
def tag_depth_counts(names)
|
|
35
|
+
names.map { it.count(':') }.tally.sort.to_h
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Print node and tag coverage
|
|
39
|
+
def stats(out: $stdout)
|
|
40
|
+
Admin.connect!
|
|
41
|
+
total = HTM::Models::Node.count
|
|
42
|
+
with_embeddings = HTM::Models::Node.exclude(embedding: nil).count
|
|
43
|
+
with_tags = HTM::Models::Node.with_tags.count
|
|
44
|
+
|
|
45
|
+
out.puts "HTM Async Job Statistics"
|
|
46
|
+
out.puts "=" * 60
|
|
47
|
+
out.puts "Total nodes: #{total}"
|
|
48
|
+
coverage_shares(total, with_embeddings, with_tags).each { |label, part| print_share(out, label, part, total) }
|
|
49
|
+
print_tag_breakdown(HTM::Models::Tag.select_map(:name), with_tags, out)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# @return [Hash{String => Integer}] node counts with and without embeddings and tags, by label
|
|
53
|
+
def coverage_shares(total, with_embeddings, with_tags)
|
|
54
|
+
{
|
|
55
|
+
"Nodes with embeddings" => with_embeddings,
|
|
56
|
+
"Nodes without embeddings" => total - with_embeddings,
|
|
57
|
+
"Nodes with tags" => with_tags,
|
|
58
|
+
"Nodes without tags" => total - with_tags
|
|
59
|
+
}
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def print_share(out, label, part, whole)
|
|
63
|
+
out.puts "#{label}: #{part} (#{Admin.percentage(part, whole)}%)"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def print_tag_breakdown(names, nodes_with_tags, out)
|
|
67
|
+
out.puts "\nTotal tags in ontology: #{names.size}"
|
|
68
|
+
unless names.empty?
|
|
69
|
+
out.puts "\nTag hierarchy breakdown:"
|
|
70
|
+
tag_depth_counts(names).each { |depth, count| out.puts " Depth #{depth}: #{count} tags" }
|
|
71
|
+
end
|
|
72
|
+
return unless nodes_with_tags.positive?
|
|
73
|
+
|
|
74
|
+
out.puts "\nAverage tags per node: #{(HTM::Models::NodeTag.count.to_f / nodes_with_tags).round(2)}"
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Generate embeddings for nodes that have none
|
|
78
|
+
#
|
|
79
|
+
# @return [Hash, nil] { ok:, failed: }, nil when nothing was pending
|
|
80
|
+
#
|
|
81
|
+
def process_embeddings(out: $stdout)
|
|
82
|
+
prepare!
|
|
83
|
+
process(nodes_without_embeddings, 'Embeddings', "embedding", out) { |node, _bar| Admin.embed!(node) }
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# Extract tags for nodes that have none
|
|
87
|
+
#
|
|
88
|
+
# @return [Hash, nil] { ok:, failed: }, nil when nothing was pending
|
|
89
|
+
#
|
|
90
|
+
def process_tags(out: $stdout)
|
|
91
|
+
prepare!
|
|
92
|
+
process(nodes_without_tags, 'Tags', "tag extraction", out) { |node, _bar| tag!(node) }
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Extract tags for +node+ (with recent tags as ontology context), link
|
|
96
|
+
# them, and rebuild the node's tag co-occurrence links as
|
|
97
|
+
# GenerateTagsJob does
|
|
98
|
+
def tag!(node)
|
|
99
|
+
ontology = HTM::Models::Tag.order(Sequel.desc(:created_at)).limit(ONTOLOGY_SIZE).select_map(:name)
|
|
100
|
+
node.add_tags(HTM::TagService.extract(node.content, existing_ontology: ontology))
|
|
101
|
+
HTM::Jobs::GenerateRelationshipsJob.perform(node_id: node.id)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Extract propositions for nodes not yet processed
|
|
105
|
+
#
|
|
106
|
+
# @return [Hash, nil] { ok:, failed:, created: }, nil when nothing was pending
|
|
107
|
+
#
|
|
108
|
+
def process_propositions(out: $stdout)
|
|
109
|
+
prepare!
|
|
110
|
+
processed = proposition_source_ids
|
|
111
|
+
pending = nodes_without_propositions(processed)
|
|
112
|
+
return none_pending(out, "proposition extraction") if pending.none?
|
|
113
|
+
|
|
114
|
+
out.puts "Processing #{pending.count} nodes for proposition extraction..."
|
|
115
|
+
out.puts "(Nodes already processed: #{processed.size})\n"
|
|
116
|
+
counts = DatabaseCommands.extract_all_propositions(pending, Admin.proposition_robot('proposition_extractor'), out)
|
|
117
|
+
Admin.print_counts("\nCompleted:", {
|
|
118
|
+
'Nodes processed' => counts[:ok],
|
|
119
|
+
'Propositions created' => counts[:created],
|
|
120
|
+
'Failed' => counts[:failed]
|
|
121
|
+
}, out:)
|
|
122
|
+
counts
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Run every process_* command in turn
|
|
126
|
+
def process_all(out: $stdout)
|
|
127
|
+
process_embeddings(out:)
|
|
128
|
+
process_tags(out:)
|
|
129
|
+
process_propositions(out:)
|
|
130
|
+
out.puts "\nAll pending jobs processed!"
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
# Regenerate the embedding of every node, after confirmation
|
|
134
|
+
#
|
|
135
|
+
# @return [Hash, nil] { ok:, failed: }, nil when cancelled or there are no nodes
|
|
136
|
+
#
|
|
137
|
+
def reprocess_embeddings(input: $stdin, out: $stdout)
|
|
138
|
+
prompt = "This will regenerate embeddings for ALL nodes. Are you sure? (yes/no): "
|
|
139
|
+
return Admin.cancelled(out) unless Admin.confirmed?(prompt, input:, out:)
|
|
140
|
+
|
|
141
|
+
prepare!
|
|
142
|
+
process(HTM::Models::Node.dataset, 'Embeddings', "embedding", out) { |node, _bar| Admin.embed!(node) }
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
# Print nodes older than STALE_AFTER still missing an embedding or tags
|
|
146
|
+
def failed(out: $stdout, now: Time.now)
|
|
147
|
+
Admin.connect!
|
|
148
|
+
cutoff = Sequel.lit('created_at < ?', now - STALE_AFTER)
|
|
149
|
+
out.puts "Nodes with Processing Issues"
|
|
150
|
+
out.puts "=" * 60
|
|
151
|
+
print_stale(nodes_without_embeddings.where(cutoff), "embeddings", out, now)
|
|
152
|
+
print_stale(nodes_without_tags.where(cutoff), "tags", out, now)
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
def print_stale(dataset, missing, out, now)
|
|
156
|
+
count = dataset.count
|
|
157
|
+
if count.zero?
|
|
158
|
+
out.puts "\n✓ No old nodes without #{missing}"
|
|
159
|
+
return
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
out.puts "\nNodes without #{missing} (>1 hour old):"
|
|
163
|
+
dataset.limit(10).each { out.puts " Node #{it.id}: created #{Admin.time_ago(it.created_at, now:)}" }
|
|
164
|
+
out.puts " ... and #{count - 10} more" if count > 10
|
|
165
|
+
end
|
|
166
|
+
|
|
167
|
+
# Clear every embedding and tag, after confirmation
|
|
168
|
+
#
|
|
169
|
+
# @return [Boolean, nil] true once cleared, nil when cancelled
|
|
170
|
+
#
|
|
171
|
+
def clear_all(input: $stdin, out: $stdout)
|
|
172
|
+
prompt = "This will clear ALL embeddings and tags. Are you sure? (yes/no): "
|
|
173
|
+
return Admin.cancelled(out) unless Admin.confirmed?(prompt, input:, out:)
|
|
174
|
+
|
|
175
|
+
Admin.connect!
|
|
176
|
+
out.puts "Clearing embeddings..."
|
|
177
|
+
HTM::Models::Node.dataset.update(embedding: nil)
|
|
178
|
+
out.puts "Clearing tags..."
|
|
179
|
+
HTM::Models::NodeTag.dataset.delete
|
|
180
|
+
HTM::Models::Tag.dataset.delete
|
|
181
|
+
out.puts "Done! All embeddings and tags cleared."
|
|
182
|
+
true
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
def prepare!
|
|
186
|
+
Admin.connect!
|
|
187
|
+
HTM.configure
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
# Run the block over +dataset+ under a progress bar and report the counts
|
|
191
|
+
def process(dataset, title, what, out, &)
|
|
192
|
+
return none_pending(out, what) if dataset.none?
|
|
193
|
+
|
|
194
|
+
out.puts "Processing #{dataset.count} pending #{what} jobs...\n"
|
|
195
|
+
counts = Admin.each_with_progress(dataset, title, out:, &)
|
|
196
|
+
Admin.print_counts("\nCompleted:", {
|
|
197
|
+
'Processed' => counts[:ok],
|
|
198
|
+
'Failed' => counts[:failed]
|
|
199
|
+
}, out:)
|
|
200
|
+
counts
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
def none_pending(out, what)
|
|
204
|
+
out.puts "No pending #{what} jobs"
|
|
205
|
+
nil
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|