Changeset 0.29.0 (#195)
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"git.gobha.me/xcaliber/chat-switchboard/database"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/knowledge"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/models"
|
||||
"git.gobha.me/xcaliber/chat-switchboard/notifications"
|
||||
@@ -70,11 +69,7 @@ func (e *Extractor) Extract(ctx context.Context, channelID, userID, teamID, pers
|
||||
}
|
||||
|
||||
// Check extraction log for last processed message
|
||||
var lastMessageID string
|
||||
row := database.DB.QueryRowContext(ctx,
|
||||
database.Q(`SELECT last_message_id FROM memory_extraction_log WHERE channel_id = $1 AND user_id = $2`),
|
||||
channelID, userID)
|
||||
row.Scan(&lastMessageID) // ignore error — may not exist yet
|
||||
lastMessageID, _ := e.stores.Memories.GetLastExtractionMessageID(ctx, channelID, userID)
|
||||
|
||||
// Load recent messages for this channel
|
||||
messages, err := e.stores.Messages.ListForChannel(ctx, channelID, store.ListOptions{Limit: 200})
|
||||
@@ -197,25 +192,7 @@ func (e *Extractor) Extract(ctx context.Context, channelID, userID, teamID, pers
|
||||
|
||||
// Update extraction log
|
||||
latestID := newMessages[len(newMessages)-1].ID
|
||||
if database.IsSQLite() {
|
||||
_, err = database.DB.ExecContext(ctx, `
|
||||
INSERT INTO memory_extraction_log (id, channel_id, user_id, last_message_id, memory_count)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
ON CONFLICT(channel_id, user_id) DO UPDATE SET
|
||||
last_message_id = excluded.last_message_id,
|
||||
extracted_at = datetime('now'),
|
||||
memory_count = memory_extraction_log.memory_count + excluded.memory_count
|
||||
`, store.NewID(), channelID, userID, latestID, saved)
|
||||
} else {
|
||||
_, err = database.DB.ExecContext(ctx, `
|
||||
INSERT INTO memory_extraction_log (channel_id, user_id, last_message_id, memory_count)
|
||||
VALUES ($1, $2, $3, $4)
|
||||
ON CONFLICT(channel_id, user_id) DO UPDATE SET
|
||||
last_message_id = EXCLUDED.last_message_id,
|
||||
extracted_at = now(),
|
||||
memory_count = memory_extraction_log.memory_count + EXCLUDED.memory_count
|
||||
`, channelID, userID, latestID, saved)
|
||||
}
|
||||
err = e.stores.Memories.UpsertExtractionLog(ctx, channelID, userID, latestID, saved)
|
||||
|
||||
if saved > 0 {
|
||||
log.Printf("✅ memory extraction: channel %s → %d facts", channelID, saved)
|
||||
@@ -241,15 +218,7 @@ func (e *Extractor) embedMemory(ctx context.Context, m *models.Memory, userID st
|
||||
}
|
||||
|
||||
vecJSON, _ := json.Marshal(result.Vectors[0])
|
||||
if database.IsSQLite() {
|
||||
database.DB.ExecContext(ctx,
|
||||
`UPDATE memories SET embedding = ? WHERE id = ?`,
|
||||
string(vecJSON), m.ID)
|
||||
} else {
|
||||
database.DB.ExecContext(ctx,
|
||||
`UPDATE memories SET embedding = $1::vector WHERE id = $2`,
|
||||
string(vecJSON), m.ID)
|
||||
}
|
||||
_ = e.stores.Memories.SetEmbedding(ctx, m.ID, string(vecJSON))
|
||||
}
|
||||
|
||||
// parseExtractionResponse parses the utility model's JSON response.
|
||||
|
||||
Reference in New Issue
Block a user