diff options
| author | Ben Sima <ben@bensima.com> | 2025-12-19 10:51:13 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-12-19 10:51:13 -0500 |
| commit | a960a0de7abc50abec51262de8a5871048817f1f (patch) | |
| tree | 973f4fbc8d75031bbb01ed1aec62a23c85fa2919 /Omni/Agent/Telegram.hs | |
| parent | 533e4209192298de4808c58f6ea6244e4bed5768 (diff) | |
Add semantic search for chat history
- Add chat_history table with embeddings in memory.db
- Add saveChatHistoryEntry for live message ingestion
- Add searchChatHistorySemantic for vector similarity search
- Update search_chat_history tool to use semantic search
- Add backfill command: run.sh Omni/Agent/Memory.hs backfill
- Add stats command: run.sh Omni/Agent/Memory.hs stats
- Change default memory.db path to ~/memory.db
- Wire Telegram message handling to save to chat_history async
Diffstat (limited to 'Omni/Agent/Telegram.hs')
| -rw-r--r-- | Omni/Agent/Telegram.hs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/Omni/Agent/Telegram.hs b/Omni/Agent/Telegram.hs index e59570a..de84e49 100644 --- a/Omni/Agent/Telegram.hs +++ b/Omni/Agent/Telegram.hs @@ -867,6 +867,9 @@ handleAuthorizedMessageContinued tgConfig provider engineCfg msg uid userName ch Memory.getConversationContext uid chatId maxConversationTokens putText <| "Conversation context: " <> tshow contextTokens <> " tokens" + now <- getCurrentTime + _ <- forkIO <| Memory.saveChatHistoryEntry chatId (Just uid) "user" (Just userName) userMessage now + processEngagedMessage tgConfig provider engineCfg msg uid userName chatId userMessage conversationContext handleAuthorizedMessageBatch :: @@ -999,6 +1002,9 @@ handleAuthorizedMessageBatch tgConfig provider engineCfg msg uid userName chatId Memory.getConversationContext uid chatId maxConversationTokens putText <| "Conversation context: " <> tshow contextTokens <> " tokens" + now <- getCurrentTime + _ <- forkIO <| Memory.saveChatHistoryEntry chatId (Just uid) "user" (Just userName) userMessage now + processEngagedMessage tgConfig provider engineCfg msg uid userName chatId userMessage conversationContext processEngagedMessage :: @@ -1212,6 +1218,11 @@ processEngagedMessage tgConfig provider engineCfg msg uid userName chatId userMe then void <| Memory.saveGroupMessage chatId threadId Memory.AssistantRole "Ava" response else void <| Memory.saveMessage uid chatId Memory.AssistantRole Nothing response + unless (Text.null response) <| do + nowResp <- getCurrentTime + _ <- forkIO <| Memory.saveChatHistoryEntry chatId (Just uid) "assistant" (Just "Ava") response nowResp + pure () + if Text.null response then do if isGroup |
