feat: enhance RAG functionality with context character limits, query rewriting options, and improved timeout settings
Build and Release / release (push) Successful in 1m31s
Build and Release / release (push) Successful in 1m31s
This commit is contained in:
@@ -176,6 +176,7 @@ func (s *chatbotService) Chat(ctx context.Context, userID string, projectID *str
|
||||
rerankStart := time.Now()
|
||||
results = s.rerankResults(ctx, searchQuery, results, contextLimit)
|
||||
rerankDuration := time.Since(rerankStart)
|
||||
results = limitRagResultsByContextChars(results, config.GetIntConfigWithDefault("RAG_CONTEXT_MAX_CHARS", 8000))
|
||||
|
||||
promptBuildStart := time.Now()
|
||||
var contextBuilder strings.Builder
|
||||
@@ -390,6 +391,34 @@ func limitRagResults(results []*models.RagChunk, limit int) []*models.RagChunk {
|
||||
return results[:limit]
|
||||
}
|
||||
|
||||
func limitRagResultsByContextChars(results []*models.RagChunk, maxChars int) []*models.RagChunk {
|
||||
if maxChars <= 0 || len(results) == 0 {
|
||||
return results
|
||||
}
|
||||
|
||||
selected := make([]*models.RagChunk, 0, len(results))
|
||||
used := 0
|
||||
for _, result := range results {
|
||||
if result == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
nextLen := len(result.Content) + 64
|
||||
if len(selected) > 0 && used+nextLen > maxChars {
|
||||
break
|
||||
}
|
||||
|
||||
selected = append(selected, result)
|
||||
used += nextLen
|
||||
}
|
||||
|
||||
if len(selected) == 0 {
|
||||
return results[:1]
|
||||
}
|
||||
|
||||
return selected
|
||||
}
|
||||
|
||||
func normalizeAnswer(s string) string {
|
||||
s = strings.TrimSpace(s)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user