From a960a0de7abc50abec51262de8a5871048817f1f Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Fri, 19 Dec 2025 10:51:13 -0500 Subject: 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 --- Omni/Agent/Telegram.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'Omni/Agent/Telegram.hs') 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 -- cgit v1.2.3