Skip to content

Commit be1ad7f

Browse files
committed
fix
1 parent 9dfa4df commit be1ad7f

File tree

3 files changed

+18
-65
lines changed

3 files changed

+18
-65
lines changed

main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ var (
9999
// CLI flags
100100
enableLLM = flag.Bool("llm", false, "Enable LLM-powered verification")
101101
modelPath = flag.String("model-path", ".gosecretscanner/models/granite-4.0-micro-Q4_K_M.gguf", "Path to LLM model")
102+
embeddingsPath = flag.String("embeddings-path", "", "Path to embeddings models directory (defaults to .gosecretscanner/models)")
102103
dbPath = flag.String("db-path", ".gosecretscanner/findings.db", "Path to vector store database")
103104
similarityThreshold = flag.Float64("similarity", 0.8, "Similarity threshold for vector search")
104105
keepVectorStore = flag.Bool("keep-vector-store", false, "Keep the vector store database after the run")
@@ -127,6 +128,7 @@ func main() {
127128
Enabled: true,
128129
DBPath: *dbPath,
129130
ModelPath: *modelPath,
131+
EmbeddingsPath: *embeddingsPath,
130132
SimilarityThreshold: float32(*similarityThreshold),
131133
EphemeralStore: !*keepVectorStore,
132134
LLMEndpoint: *llmEndpoint,

pkg/verification/pipeline.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ type Config struct {
2727
Enabled bool
2828
DBPath string
2929
ModelPath string
30+
EmbeddingsPath string // Path to embeddings models directory
3031
SimilarityThreshold float32
3132
EphemeralStore bool
3233
LLMEndpoint string
@@ -44,8 +45,17 @@ func NewPipeline(config *Config) (*Pipeline, error) {
4445
embeddingGen := embeddings.NewEmbeddingGenerator(config.Enabled)
4546

4647
// Initialize BGE embeddings with ONNX model
47-
if config.Enabled && config.ModelPath != "" {
48-
modelsDir := filepath.Dir(config.ModelPath)
48+
// Use EmbeddingsPath if specified, otherwise try to derive from ModelPath, or default to .gosecretscanner/models
49+
if config.Enabled {
50+
var modelsDir string
51+
if config.EmbeddingsPath != "" {
52+
modelsDir = config.EmbeddingsPath
53+
} else if config.ModelPath != "" {
54+
modelsDir = filepath.Dir(config.ModelPath)
55+
} else {
56+
modelsDir = ".gosecretscanner/models"
57+
}
58+
4959
if err := embeddingGen.Initialize(modelsDir); err != nil {
5060
// Non-fatal: fall back to hash-based embeddings
5161
fmt.Printf("Warning: failed to initialize BGE embeddings, using hash-based fallback: %v\n", err)
@@ -105,12 +115,15 @@ func (p *Pipeline) VerifyFinding(
105115
return nil, fmt.Errorf("failed to parse file: %w", err)
106116
}
107117

118+
// Get surrounding code context (±5 lines)
119+
surroundingCode := p.parser.GetContext(content, lineNumber, 5)
120+
108121
// Create code context
109122
codeContext := &llm.CodeContext{
110123
FilePath: filePath,
111124
Language: parsed.Language,
112125
Function: p.findFunction(parsed, lineNumber),
113-
SurroundingCode: line,
126+
SurroundingCode: surroundingCode,
114127
Imports: parsed.Imports,
115128
IsTest: parsed.IsTest,
116129
}

test/test_embeddings.go

Lines changed: 0 additions & 62 deletions
This file was deleted.

0 commit comments

Comments
 (0)