Documentation
¶
Index ¶
- func FilterProfileFacts(facts []storage.Fact) []storage.Fact
- func FormatRecentTopics(topics []storage.TopicExtended) string
- func FormatUserProfile(facts []storage.Fact) string
- func RecordEmbeddingRequest(userID int64, model string, embeddingType string, durationSeconds float64, ...)
- func RecordRAGCandidates(userID int64, searchType string, count int)
- func RecordRAGEnrichment(userID int64, durationSeconds float64)
- func RecordRAGLatency(userID int64, source string, durationSeconds float64)
- func RecordRAGRetrieval(userID int64, hasContext bool)
- func RecordRerankerCandidatesInput(userID int64, count int)
- func RecordRerankerCandidatesOutput(userID int64, count int)
- func RecordRerankerCost(userID int64, cost float64)
- func RecordRerankerDuration(userID int64, durationSeconds float64)
- func RecordRerankerFallback(userID int64, reason string)
- func RecordRerankerHallucination(userID int64, count int)
- func RecordRerankerToolCalls(userID int64, count int)
- func RecordVectorSearch(userID int64, searchType string, durationSeconds float64, vectorsScanned int)
- func UpdateVectorIndexMetrics(topicsCount, factsCount, peopleCount int)
- type ActiveSessionInfo
- type ContaminationFixStats
- type ContaminationInfo
- type DatabaseHealth
- type ExtractedTopic
- type FactVectorItem
- type OverlappingPair
- type PersonSearchResult
- type PersonVectorItem
- type ProcessingStats
- type ProgressCallback
- type ProgressEvent
- type RepairStats
- type RetrievalDebugInfo
- type RetrievalOptions
- type RetrievalResult
- type SearchResult
- type Service
- func (s *Service) FindSimilarFacts(ctx context.Context, userID int64, embedding []float32, threshold float32) ([]storage.Fact, error)
- func (s *Service) FixContamination(ctx context.Context, userID int64, dryRun bool) (*ContaminationFixStats, error)
- func (s *Service) ForceProcessUser(ctx context.Context, userID int64) (int, error)
- func (s *Service) ForceProcessUserWithProgress(ctx context.Context, userID int64, onProgress ProgressCallback) (*ProcessingStats, error)
- func (s *Service) GetActiveSessions() ([]ActiveSessionInfo, error)
- func (s *Service) GetContaminationInfo(ctx context.Context, userID int64) (*ContaminationInfo, error)
- func (s *Service) GetDatabaseHealth(ctx context.Context, userID int64, largeThreshold int) (*DatabaseHealth, error)
- func (s *Service) GetRecentTopics(userID int64, limit int) ([]storage.TopicExtended, error)
- func (s *Service) LoadNewVectors() error
- func (s *Service) ReloadVectors() error
- func (s *Service) RepairDatabase(ctx context.Context, userID int64, dryRun bool) (*RepairStats, error)
- func (s *Service) Retrieve(ctx context.Context, userID int64, query string, opts *RetrievalOptions) (*RetrievalResult, *RetrievalDebugInfo, error)
- func (s *Service) RetrieveFacts(ctx context.Context, userID int64, query string) ([]storage.Fact, error)
- func (s *Service) SearchPeople(ctx context.Context, userID int64, embedding []float32, threshold float32, ...) ([]PersonSearchResult, error)
- func (s *Service) SetAgentLogger(logger *agentlog.Logger)
- func (s *Service) SetEnricherAgent(a agent.Agent)
- func (s *Service) SetMergerAgent(a agent.Agent)
- func (s *Service) SetPeopleRepository(pr storage.PeopleRepository)
- func (s *Service) SetRerankerAgent(a agent.Agent)
- func (s *Service) SetSplitterAgent(a agent.Agent)
- func (s *Service) SplitLargeTopics(ctx context.Context, userID int64, thresholdChars int) (*SplitStats, error)
- func (s *Service) Start(ctx context.Context) error
- func (s *Service) Stop()
- func (s *Service) TriggerConsolidation()
- type SplitStats
- type TestMessageResult
- type TopicInfo
- type TopicSearchResult
- type TopicVectorItem
- type UsageInfo
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FilterProfileFacts ¶ added in v0.4.8
FilterProfileFacts filters facts to identity and high-importance facts only. Delegates to storage.FilterProfileFacts.
func FormatRecentTopics ¶ added in v0.4.8
func FormatRecentTopics(topics []storage.TopicExtended) string
FormatRecentTopics formats recent topics for inclusion in agent prompts. Delegates to storage.FormatRecentTopics.
func FormatUserProfile ¶ added in v0.4.8
FormatUserProfile formats user facts for inclusion in agent prompts. Delegates to storage.FormatUserProfile.
func RecordEmbeddingRequest ¶ added in v0.3.0
func RecordEmbeddingRequest(userID int64, model string, embeddingType string, durationSeconds float64, success bool, tokens int, cost *float64)
RecordEmbeddingRequest записывает метрики embedding запроса. embeddingType: searchTypeTopics или searchTypeFacts
func RecordRAGCandidates ¶ added in v0.3.3
RecordRAGCandidates записывает количество кандидатов до фильтрации.
func RecordRAGEnrichment ¶ added in v0.3.7
RecordRAGEnrichment записывает время LLM вызова для обогащения запроса.
func RecordRAGLatency ¶ added in v0.3.6
RecordRAGLatency записывает общее время RAG retrieval. source: "auto" для buildContext, "tool" для search_history tool.
func RecordRAGRetrieval ¶ added in v0.3.0
RecordRAGRetrieval записывает результат RAG retrieval.
func RecordRerankerCandidatesInput ¶ added in v0.4.1
RecordRerankerCandidatesInput записывает кандидатов на входе.
func RecordRerankerCandidatesOutput ¶ added in v0.4.1
RecordRerankerCandidatesOutput записывает кандидатов на выходе.
func RecordRerankerCost ¶ added in v0.4.1
RecordRerankerCost записывает стоимость reranker.
func RecordRerankerDuration ¶ added in v0.4.1
RecordRerankerDuration записывает время reranker операции.
func RecordRerankerFallback ¶ added in v0.4.1
RecordRerankerFallback записывает срабатывание fallback. reason: "timeout", "error", "max_tool_calls", "invalid_json", "requested_ids", "vector_top", "all_hallucinated"
func RecordRerankerHallucination ¶ added in v0.4.8
RecordRerankerHallucination записывает количество галлюцинированных topic IDs.
func RecordRerankerToolCalls ¶ added in v0.4.1
RecordRerankerToolCalls записывает количество tool calls.
func RecordVectorSearch ¶ added in v0.3.0
func RecordVectorSearch(userID int64, searchType string, durationSeconds float64, vectorsScanned int)
RecordVectorSearch записывает метрики vector search.
func UpdateVectorIndexMetrics ¶ added in v0.3.0
func UpdateVectorIndexMetrics(topicsCount, factsCount, peopleCount int)
UpdateVectorIndexMetrics обновляет метрики размера индекса.
Types ¶
type ActiveSessionInfo ¶ added in v0.3.0
type ActiveSessionInfo struct {
UserID int64
MessageCount int
FirstMessageTime time.Time
LastMessageTime time.Time
ContextSize int // Total characters in session messages
}
ActiveSessionInfo contains information about unprocessed messages for a user.
type ContaminationFixStats ¶ added in v0.4.6
type ContaminationFixStats struct {
MessagesUnlinked int64 `json:"messages_unlinked"`
OrphanedTopicsDeleted int `json:"orphaned_topics_deleted"`
}
ContaminationFixStats contains statistics about contamination repair.
type ContaminationInfo ¶ added in v0.4.6
type ContaminationInfo struct {
TotalContaminated int `json:"total_contaminated"`
ContaminatedTopics []storage.ContaminatedTopic `json:"contaminated_topics"`
}
ContaminationInfo contains information about cross-user data contamination.
type DatabaseHealth ¶ added in v0.4.6
type DatabaseHealth struct {
TotalTopics int `json:"total_topics"`
OrphanedTopics int `json:"orphaned_topics"`
ZeroSizeTopics int `json:"zero_size_topics"`
LargeTopics int `json:"large_topics"`
OverlappingPairs int `json:"overlapping_pairs"`
FactsOnOrphaned int `json:"facts_on_orphaned"`
AvgTopicSize int `json:"avg_topic_size"`
LargeTopicsList []TopicInfo `json:"large_topics_list,omitempty"`
OverlappingPairsList []OverlappingPair `json:"overlapping_pairs_list,omitempty"`
}
DatabaseHealth contains diagnostic information about the database.
type ExtractedTopic ¶
type FactVectorItem ¶
FactVectorItem stores a fact's embedding for vector search.
type OverlappingPair ¶ added in v0.4.6
type OverlappingPair struct {
Topic1ID int64 `json:"topic1_id"`
Topic1Summary string `json:"topic1_summary"`
Topic2ID int64 `json:"topic2_id"`
Topic2Summary string `json:"topic2_summary"`
}
OverlappingPair contains information about two overlapping topics.
type PersonSearchResult ¶ added in v0.5.1
PersonSearchResult represents a matched person with their score.
type PersonVectorItem ¶ added in v0.5.1
PersonVectorItem stores a person's embedding for vector search.
type ProcessingStats ¶ added in v0.3.0
type ProcessingStats struct {
MessagesProcessed int `json:"messages_processed"`
TopicsExtracted int `json:"topics_extracted"`
TopicsMerged int `json:"topics_merged"`
FactsCreated int `json:"facts_created"`
FactsUpdated int `json:"facts_updated"`
FactsDeleted int `json:"facts_deleted"`
// People stats (v0.5.1)
PeopleAdded int `json:"people_added"`
PeopleUpdated int `json:"people_updated"`
PeopleMerged int `json:"people_merged"`
// Usage stats from API calls
PromptTokens int `json:"prompt_tokens"`
CompletionTokens int `json:"completion_tokens"`
EmbeddingTokens int `json:"embedding_tokens"`
TotalCost *float64 `json:"total_cost,omitempty"` // Cost in USD
}
ProcessingStats contains detailed statistics about session processing.
func (*ProcessingStats) AddChatUsage ¶ added in v0.3.0
func (s *ProcessingStats) AddChatUsage(promptTokens, completionTokens int, cost *float64)
AddChatUsage adds usage from a chat completion response.
func (*ProcessingStats) AddEmbeddingUsage ¶ added in v0.3.0
func (s *ProcessingStats) AddEmbeddingUsage(tokens int, cost *float64)
AddEmbeddingUsage adds usage from an embedding response.
type ProgressCallback ¶ added in v0.3.0
type ProgressCallback func(event ProgressEvent)
ProgressCallback is called during processing to report progress.
type ProgressEvent ¶ added in v0.3.0
type ProgressEvent struct {
Stage string `json:"stage"` // "topics", "consolidation", "facts"
Current int `json:"current"` // Current item being processed
Total int `json:"total"` // Total items to process
Message string `json:"message"` // Human-readable status message
Complete bool `json:"complete"` // True when processing is complete
Stats *ProcessingStats `json:"stats,omitempty"` // Final stats when complete
}
ProgressEvent represents a progress update during processing.
type RepairStats ¶ added in v0.4.6
type RepairStats struct {
OrphanedTopicsDeleted int `json:"orphaned_topics_deleted"`
FactsRelinked int `json:"facts_relinked"`
RangesRecalculated int `json:"ranges_recalculated"`
SizesRecalculated int `json:"sizes_recalculated"`
}
RepairStats contains statistics about repair operations.
type RetrievalDebugInfo ¶
type RetrievalDebugInfo struct {
OriginalQuery string
EnrichedQuery string
EnrichmentPrompt string
EnrichmentTokens int
Results []TopicSearchResult
}
RetrievalDebugInfo contains trace data for RAG debugging
type RetrievalOptions ¶
type RetrievalResult ¶ added in v0.5.1
type RetrievalResult struct {
Topics []TopicSearchResult
People []storage.Person // Selected by reranker (excludes inner circle)
}
RetrievalResult contains both topics and selected people from RAG retrieval.
type SearchResult ¶
SearchResult kept for backward compatibility if needed, but we are moving to TopicSearchResult. We remove it to force type errors in other files to fix them.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service provides RAG (Retrieval-Augmented Generation) functionality.
func NewService ¶
func NewService(logger *slog.Logger, cfg *config.Config, topicRepo storage.TopicRepository, factRepo storage.FactRepository, factHistoryRepo storage.FactHistoryRepository, msgRepo storage.MessageRepository, maintenanceRepo storage.MaintenanceRepository, client openrouter.Client, memoryService *memory.Service, translator *i18n.Translator) *Service
NewService creates a new RAG service.
func (*Service) FindSimilarFacts ¶
func (*Service) FixContamination ¶ added in v0.4.6
func (s *Service) FixContamination(ctx context.Context, userID int64, dryRun bool) (*ContaminationFixStats, error)
FixContamination removes foreign messages from contaminated topics. If userID is 0, fixes all users.
func (*Service) ForceProcessUser ¶
func (*Service) ForceProcessUserWithProgress ¶ added in v0.3.0
func (s *Service) ForceProcessUserWithProgress(ctx context.Context, userID int64, onProgress ProgressCallback) (*ProcessingStats, error)
ForceProcessUserWithProgress processes all unprocessed messages for a user with progress reporting. Unlike ForceProcessUser, this runs consolidation and fact extraction synchronously.
func (*Service) GetActiveSessions ¶ added in v0.3.0
func (s *Service) GetActiveSessions() ([]ActiveSessionInfo, error)
GetActiveSessions returns information about unprocessed messages (active sessions) for all users.
func (*Service) GetContaminationInfo ¶ added in v0.4.6
func (s *Service) GetContaminationInfo(ctx context.Context, userID int64) (*ContaminationInfo, error)
GetContaminationInfo returns information about cross-user data contamination. If userID is 0, checks all users.
func (*Service) GetDatabaseHealth ¶ added in v0.4.6
func (s *Service) GetDatabaseHealth(ctx context.Context, userID int64, largeThreshold int) (*DatabaseHealth, error)
GetDatabaseHealth returns diagnostic information about database health. If userID is 0, returns stats for all users.
func (*Service) GetRecentTopics ¶ added in v0.4.6
GetRecentTopics returns the N most recent topics for a user with message counts.
func (*Service) LoadNewVectors ¶ added in v0.2.1
LoadNewVectors incrementally loads only new topics, facts, and people since last load.
func (*Service) ReloadVectors ¶
ReloadVectors fully reloads all topic, fact, and people vectors from the database.
func (*Service) RepairDatabase ¶ added in v0.4.6
func (s *Service) RepairDatabase(ctx context.Context, userID int64, dryRun bool) (*RepairStats, error)
RepairDatabase fixes database integrity issues.
func (*Service) Retrieve ¶
func (s *Service) Retrieve(ctx context.Context, userID int64, query string, opts *RetrievalOptions) (*RetrievalResult, *RetrievalDebugInfo, error)
func (*Service) RetrieveFacts ¶
func (*Service) SearchPeople ¶ added in v0.5.1
func (s *Service) SearchPeople(ctx context.Context, userID int64, embedding []float32, threshold float32, maxResults int, excludeCircles []string) ([]PersonSearchResult, error)
SearchPeople searches for people by vector similarity (v0.5.1). excludeCircles filters out people from specified circles (e.g., "Work_Inner", "Family").
func (*Service) SetAgentLogger ¶ added in v0.4.8
SetAgentLogger sets the agent logger for debugging LLM calls.
func (*Service) SetEnricherAgent ¶ added in v0.5.0
SetEnricherAgent sets the query enrichment agent.
func (*Service) SetMergerAgent ¶ added in v0.5.0
SetMergerAgent sets the topic merging agent.
func (*Service) SetPeopleRepository ¶ added in v0.5.1
func (s *Service) SetPeopleRepository(pr storage.PeopleRepository)
SetPeopleRepository sets the people repository for person search (v0.5.1).
func (*Service) SetRerankerAgent ¶ added in v0.5.0
SetRerankerAgent sets the topic reranking agent.
func (*Service) SetSplitterAgent ¶ added in v0.5.0
SetSplitterAgent sets the topic splitting agent.
func (*Service) SplitLargeTopics ¶ added in v0.4.6
func (s *Service) SplitLargeTopics(ctx context.Context, userID int64, thresholdChars int) (*SplitStats, error)
SplitLargeTopics finds and splits all topics larger than threshold. If userID is 0, processes all users.
func (*Service) TriggerConsolidation ¶
func (s *Service) TriggerConsolidation()
TriggerConsolidation triggers a consolidation run.
type SplitStats ¶ added in v0.4.6
type SplitStats struct {
TopicsProcessed int
TopicsCreated int
FactsRelinked int
PromptTokens int
CompletionTokens int
EmbeddingTokens int
TotalCost *float64
}
SplitStats contains statistics about topic splitting.
func (*SplitStats) AddCost ¶ added in v0.4.6
func (s *SplitStats) AddCost(cost *float64)
AddCost adds cost to stats.
type TestMessageResult ¶ added in v0.3.0
type TestMessageResult struct {
Response string
TimingTotal time.Duration
TimingEmbedding time.Duration
TimingSearch time.Duration
TimingLLM time.Duration
PromptTokens int
CompletionTokens int
TotalCost float64
TopicsMatched int
FactsInjected int
ContextPreview string
RAGDebugInfo *RetrievalDebugInfo
}
TestMessageResult contains the result of a test message sent through the bot pipeline. Used by the debug chat interface to display detailed metrics.
type TopicInfo ¶ added in v0.4.6
type TopicInfo struct {
ID int64 `json:"id"`
SizeChars int `json:"size_chars"`
Summary string `json:"summary"`
}
TopicInfo contains brief topic information for display.
type TopicSearchResult ¶
type TopicSearchResult struct {
Topic storage.Topic
Score float32
Messages []storage.Message
Reason string // Why reranker chose this topic (empty if no reason provided)
}
TopicSearchResult represents a matched topic with its messages
type TopicVectorItem ¶
TopicVectorItem stores a topic's embedding for vector search.