Skip to content

Commit 76562dd

Browse files
committed
Add additional deps
1 parent 02d339c commit 76562dd

File tree

11 files changed

+436
-142
lines changed

11 files changed

+436
-142
lines changed

cmd/ask.go

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"path/filepath"
1010
"strings"
1111

12-
"github.com/blevesearch/bleve/v2"
12+
"github.com/chand1012/memory"
1313
"github.com/spf13/cobra"
1414

1515
"github.com/chand1012/ottodocs/pkg/ai"
@@ -55,19 +55,16 @@ Requires a path to a repository or file as a positional argument.`,
5555
// check if the first arg is a file or a directory
5656
// if it's a file, ask a question about that file directly
5757
if info.IsDir() {
58-
var index bleve.Index
59-
var err error
60-
mapping := bleve.NewIndexMapping()
61-
62-
// check if .index.bleve exists
63-
// if it does, load it
64-
// if it doesn't, create it
65-
// fmt.Println("Indexing repo...")
66-
index, err = bleve.New(filepath.Join(args[0], ".index.bleve"), mapping)
58+
// Define a temporary path for the index file
59+
testIndexPath := filepath.Join(args[0], ".index.memory")
60+
61+
// Create a new memory index
62+
m, _, err := memory.New(testIndexPath)
6763
if err != nil {
68-
log.Errorf("Error creating index: %s", err)
64+
log.Errorf("Failed to create memory index: %s", err)
6965
os.Exit(1)
7066
}
67+
7168
// index the repo
7269
repo, err := utils.GetRepo(repoPath, ignoreFilePath, ignoreGitignore)
7370
if err != nil {
@@ -77,52 +74,25 @@ Requires a path to a repository or file as a positional argument.`,
7774

7875
// index the files
7976
for _, file := range repo.Files {
80-
err = index.Index(file.Path, file)
77+
err = m.Add(file.Path, file.Contents)
8178
if err != nil {
8279
log.Errorf("Error indexing file: %s", err)
8380
os.Exit(1)
8481
}
8582
}
8683

87-
// ask a question about the repo
88-
query := bleve.NewQueryStringQuery(chatPrompt)
89-
search := bleve.NewSearchRequest(query)
90-
searchResults, err := index.Search(search)
84+
// search the memory index
85+
results, err := m.Search(chatPrompt)
9186
if err != nil {
92-
log.Errorf("Error searching index: %s", err)
87+
log.Errorf("Failed to search memory index: %s", err)
9388
os.Exit(1)
9489
}
9590

96-
// tokenize the question
97-
tokens := utils.SimpleTokenize(chatPrompt)
98-
for _, token := range tokens {
99-
query := bleve.NewQueryStringQuery(token)
100-
search := bleve.NewSearchRequest(query)
101-
r, err := index.Search(search)
102-
if err != nil {
103-
log.Errorf("Error searching index: %s", err)
104-
os.Exit(1)
105-
}
106-
// combines the searches, but doesn't weight by ID
107-
searchResults.Merge(r)
108-
}
109-
hits := make(map[string]float64)
110-
111-
for _, results := range searchResults.Hits {
112-
currentScore := hits[results.ID]
113-
hits[results.ID] = currentScore + results.Score
114-
}
115-
116-
var bestHit string
117-
var bestScore float64
118-
for hit, score := range hits {
119-
if score > bestScore {
120-
bestScore = score
121-
bestHit = hit
122-
}
123-
}
91+
m.Destroy()
12492

125-
fileName = bestHit
93+
// get the top fragment by average score
94+
top := memory.TopFragmentAvg(results)
95+
fileName = top.ID
12696
} else {
12797
fileName = repoPath
12898
}
@@ -143,15 +113,6 @@ Requires a path to a repository or file as a positional argument.`,
143113
}
144114

145115
fmt.Println(resp)
146-
147-
// if .index.bleve exists, delete it
148-
if _, err := os.Stat(filepath.Join(args[0], ".index.bleve")); err == nil {
149-
err = os.RemoveAll(filepath.Join(args[0], ".index.bleve"))
150-
if err != nil {
151-
log.Errorf("Error deleting index: %s", err)
152-
os.Exit(1)
153-
}
154-
}
155116
},
156117
}
157118

go.mod

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,57 +4,74 @@ go 1.20
44

55
require (
66
github.com/CasualCodersProjects/gopenai v0.3.0
7-
github.com/blevesearch/bleve/v2 v2.3.7
8-
github.com/chand1012/git2gpt v0.4.0
7+
github.com/chand1012/git2gpt v0.4.1
8+
github.com/chand1012/memory v0.3.0
99
github.com/charmbracelet/log v0.2.1
10+
github.com/go-git/go-git/v5 v5.6.1
1011
github.com/pandodao/tokenizer-go v0.1.0
1112
github.com/spf13/cobra v1.7.0
1213
)
1314

1415
require (
15-
github.com/RoaringBitmap/roaring v0.9.4 // indirect
16+
github.com/Microsoft/go-winio v0.6.1 // indirect
17+
github.com/ProtonMail/go-crypto v0.0.0-20230417170513-8ee5748c52b5 // indirect
18+
github.com/RoaringBitmap/roaring v1.2.3 // indirect
19+
github.com/acomagu/bufpipe v1.0.4 // indirect
1620
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
17-
github.com/bits-and-blooms/bitset v1.2.0 // indirect
18-
github.com/blevesearch/bleve_index_api v1.0.5 // indirect
19-
github.com/blevesearch/geo v0.1.17 // indirect
21+
github.com/bits-and-blooms/bitset v1.6.0 // indirect
22+
github.com/blevesearch/bleve v1.0.14 // indirect
2023
github.com/blevesearch/go-porterstemmer v1.0.3 // indirect
21-
github.com/blevesearch/gtreap v0.1.1 // indirect
2224
github.com/blevesearch/mmap-go v1.0.4 // indirect
23-
github.com/blevesearch/scorch_segment_api/v2 v2.1.4 // indirect
2425
github.com/blevesearch/segment v0.9.1 // indirect
2526
github.com/blevesearch/snowballstem v0.9.0 // indirect
26-
github.com/blevesearch/upsidedown_store_api v1.0.2 // indirect
27-
github.com/blevesearch/vellum v1.0.9 // indirect
28-
github.com/blevesearch/zapx/v11 v11.3.7 // indirect
29-
github.com/blevesearch/zapx/v12 v12.3.7 // indirect
30-
github.com/blevesearch/zapx/v13 v13.3.7 // indirect
31-
github.com/blevesearch/zapx/v14 v14.3.7 // indirect
32-
github.com/blevesearch/zapx/v15 v15.3.9 // indirect
27+
github.com/blevesearch/zap/v11 v11.0.14 // indirect
28+
github.com/blevesearch/zap/v12 v12.0.14 // indirect
29+
github.com/blevesearch/zap/v13 v13.0.6 // indirect
30+
github.com/blevesearch/zap/v14 v14.0.5 // indirect
31+
github.com/blevesearch/zap/v15 v15.0.3 // indirect
3332
github.com/charmbracelet/lipgloss v0.7.1 // indirect
33+
github.com/cloudflare/circl v1.3.2 // indirect
34+
github.com/couchbase/vellum v1.0.2 // indirect
3435
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
3536
github.com/dlclark/regexp2 v1.8.1 // indirect
3637
github.com/dop251/goja v0.0.0-20230304130813-e2f543bf4b4c // indirect
3738
github.com/dop251/goja_nodejs v0.0.0-20230226152057-060fa99b809f // indirect
39+
github.com/emirpasic/gods v1.18.1 // indirect
40+
github.com/go-git/gcfg v1.5.0 // indirect
41+
github.com/go-git/go-billy/v5 v5.4.1 // indirect
3842
github.com/go-logfmt/logfmt v0.6.0 // indirect
3943
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
4044
github.com/gobwas/glob v0.2.3 // indirect
41-
github.com/golang/geo v0.0.0-20210211234256-740aa86cb551 // indirect
42-
github.com/golang/protobuf v1.3.2 // indirect
43-
github.com/golang/snappy v0.0.1 // indirect
45+
github.com/golang/protobuf v1.5.3 // indirect
46+
github.com/golang/snappy v0.0.4 // indirect
4447
github.com/google/pprof v0.0.0-20230309165930-d61513b1440d // indirect
48+
github.com/imdario/mergo v0.3.15 // indirect
4549
github.com/inconshreveable/mousetrap v1.1.0 // indirect
46-
github.com/json-iterator/go v0.0.0-20171115153421-f7279a603ede // indirect
50+
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
51+
github.com/kevinburke/ssh_config v1.2.0 // indirect
4752
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
4853
github.com/mattn/go-isatty v0.0.18 // indirect
4954
github.com/mattn/go-runewidth v0.0.14 // indirect
5055
github.com/mschoch/smat v0.2.0 // indirect
5156
github.com/muesli/reflow v0.3.0 // indirect
5257
github.com/muesli/termenv v0.15.1 // indirect
58+
github.com/pjbgf/sha1cd v0.3.0 // indirect
5359
github.com/rivo/uniseg v0.2.0 // indirect
5460
github.com/russross/blackfriday/v2 v2.1.0 // indirect
61+
github.com/sergi/go-diff v1.3.1 // indirect
62+
github.com/skeema/knownhosts v1.1.0 // indirect
5563
github.com/spf13/pflag v1.0.5 // indirect
56-
go.etcd.io/bbolt v1.3.5 // indirect
57-
golang.org/x/sys v0.6.0 // indirect
58-
golang.org/x/text v0.8.0 // indirect
64+
github.com/steveyen/gtreap v0.1.0 // indirect
65+
github.com/willf/bitset v1.1.11 // indirect
66+
github.com/xanzy/ssh-agent v0.3.3 // indirect
67+
go.etcd.io/bbolt v1.3.7 // indirect
68+
golang.org/x/crypto v0.8.0 // indirect
69+
golang.org/x/mod v0.10.0 // indirect
70+
golang.org/x/net v0.9.0 // indirect
71+
golang.org/x/sys v0.7.0 // indirect
72+
golang.org/x/text v0.9.0 // indirect
73+
golang.org/x/tools v0.8.0 // indirect
74+
google.golang.org/protobuf v1.30.0 // indirect
75+
gopkg.in/warnings.v0 v0.1.2 // indirect
5976
gopkg.in/yaml.v3 v3.0.1 // indirect
6077
)

0 commit comments

Comments
 (0)