Chore: fix linter complaints

This commit is contained in:
Grail Finder
2025-10-21 10:44:07 +03:00
parent 6a8e854ef6
commit 428c45da16
6 changed files with 35 additions and 36 deletions

View File

@@ -3,6 +3,7 @@ package rag
import (
"bytes"
"encoding/json"
"errors"
"fmt"
"gf-lt/config"
"log/slog"
@@ -69,7 +70,7 @@ func (a *APIEmbedder) Embed(text []string) ([][]float32, error) {
}
if len(emb) == 0 {
err = fmt.Errorf("empty embedding response")
err = errors.New("empty embedding response")
a.logger.Error("empty embedding response")
return nil, err
}
@@ -83,7 +84,7 @@ func (a *APIEmbedder) EmbedSingle(text string) ([]float32, error) {
return nil, err
}
if len(result) == 0 {
return nil, fmt.Errorf("no embeddings returned")
return nil, errors.New("no embeddings returned")
}
return result[0], nil
}

View File

@@ -1,6 +1,7 @@
package rag
import (
"errors"
"fmt"
"gf-lt/config"
"gf-lt/models"
@@ -108,7 +109,7 @@ func (r *RAG) LoadRAG(fpath string) error {
}
if len(paragraphs) == 0 {
return fmt.Errorf("no valid paragraphs found in file")
return errors.New("no valid paragraphs found in file")
}
var (
@@ -222,7 +223,7 @@ func (r *RAG) fetchEmb(lines []string, errCh chan error, vectorCh chan<- []model
}
if len(embeddings) == 0 {
err := fmt.Errorf("no embeddings returned")
err := errors.New("no embeddings returned")
r.logger.Error("empty embeddings")
errCh <- err
return err

View File

@@ -141,7 +141,7 @@ func (vs *VectorStorage) SearchClosest(query []float32) ([]models.VectorRow, err
// we'll implement batching and potentially add L2 distance-based pre-filtering
// since cosine similarity is related to L2 distance for normalized vectors
querySQL := fmt.Sprintf("SELECT embeddings, slug, raw_text, filename FROM %s", tableName)
querySQL := "SELECT embeddings, slug, raw_text, filename FROM " + tableName
rows, err := vs.sqlxDB.Query(querySQL)
if err != nil {
return nil, err
@@ -198,7 +198,7 @@ func (vs *VectorStorage) SearchClosest(query []float32) ([]models.VectorRow, err
}
// Convert back to VectorRow slice
var results []models.VectorRow
results := make([]models.VectorRow, 0, len(topResults))
for _, result := range topResults {
result.vector.Distance = result.distance
results = append(results, result.vector)
@@ -209,11 +209,11 @@ func (vs *VectorStorage) SearchClosest(query []float32) ([]models.VectorRow, err
// ListFiles returns a list of all loaded files
func (vs *VectorStorage) ListFiles() ([]string, error) {
var fileLists [][]string
fileLists := make([][]string, 0)
// Query both tables and combine results
for _, table := range []string{"embeddings_384", "embeddings_5120"} {
query := fmt.Sprintf("SELECT DISTINCT filename FROM %s", table)
query := "SELECT DISTINCT filename FROM " + table
rows, err := vs.sqlxDB.Query(query)
if err != nil {
// Continue if one table doesn't exist