From 75003b95342eb6a9ac9b5a81c7fc83930e62a6ea Mon Sep 17 00:00:00 2001 From: "Christoph K." Date: Thu, 12 Mar 2026 19:20:05 +0100 Subject: [PATCH] ingst chat message added --- cmd/discord/main.go | 33 +++++++++++++++++++++++++++++++++ internal/brain/ingest.go | 17 +++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/cmd/discord/main.go b/cmd/discord/main.go index 7e66b98..bd6a1fb 100644 --- a/cmd/discord/main.go +++ b/cmd/discord/main.go @@ -37,6 +37,18 @@ var ( Name: "ingest", Description: "Importiert Markdown-Notizen aus brain_root in die Wissensdatenbank", }, + { + Name: "remember", + Description: "Speichert eine Nachricht in der Wissensdatenbank", + Options: []*discordgo.ApplicationCommandOption{ + { + Type: discordgo.ApplicationCommandOptionString, + Name: "text", + Description: "Der Text, der gespeichert werden soll", + Required: true, + }, + }, + }, } ) @@ -107,6 +119,8 @@ func onInteraction(s *discordgo.Session, i *discordgo.InteractionCreate) { handleAsk(s, i, i.ApplicationCommandData().Options[0].StringValue()) case "ingest": handleIngest(s, i) + case "remember": + handleRemember(s, i) } } @@ -170,6 +184,25 @@ func handleIngest(s *discordgo.Session, i *discordgo.InteractionCreate) { }) } +func handleRemember(s *discordgo.Session, i *discordgo.InteractionCreate) { + s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{ + Type: discordgo.InteractionResponseDeferredChannelMessageWithSource, + }) + + text := i.ApplicationCommandData().Options[0].StringValue() + author := i.Member.User.Username + source := fmt.Sprintf("discord/#%s", i.ChannelID) + + err := brain.IngestChatMessage(text, author, source) + var msg string + if err != nil { + msg = fmt.Sprintf("❌ Fehler beim Speichern: %v", err) + } else { + msg = fmt.Sprintf("✅ Gespeichert: _%s_", text) + } + s.InteractionResponseEdit(i.Interaction, &discordgo.WebhookEdit{Content: &msg}) +} + func queryAndFormat(question string) string { answer, chunks, err := brain.AskQuery(question) if err != nil { diff --git a/internal/brain/ingest.go b/internal/brain/ingest.go index 60d76be..9786053 100755 --- a/internal/brain/ingest.go +++ b/internal/brain/ingest.go @@ -234,4 +234,21 @@ func ingestChunks(ctx context.Context, embClient *openai.Client, pointsClient pb return err } +// IngestChatMessage speichert eine einzelne Chat-Nachricht in Qdrant. +func IngestChatMessage(text, author, source string) error { + ctx := context.Background() + ctx = metadata.AppendToOutgoingContext(ctx, "api-key", config.Cfg.Qdrant.APIKey) + + embClient := config.NewEmbeddingClient() + conn := config.NewQdrantConn() + defer conn.Close() + + ensureCollection(ctx, pb.NewCollectionsClient(conn)) + pointsClient := pb.NewPointsClient(conn) + + fullText := fmt.Sprintf("[%s] %s", author, text) + c := chunk{Text: fullText, Source: source, Type: "chat"} + return ingestChunks(ctx, embClient, pointsClient, []chunk{c}) +} + func boolPtr(b bool) *bool { return &b }