Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Fix large neighbor and search result lookups failing with SQLite's SQL variable limit. Thanks @masatohoshino for reporting.

## 0.15.2 - 2026-10-16

**Highlights:** Reliable local database initialization inside Git worktrees and refreshed dependencies.
Expand Down
2 changes: 2 additions & 0 deletions docs/clustering.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ gitcrawl neighbors owner/repo --number 123 --limit 10

Useful for "what else looks like this?" without committing to a cluster. If the source row is present but lacks a current embedding, the CLI command backfills that one row when an OpenAI key is configured; otherwise it prints the exact `gitcrawl embed --number ... --limit 1` command to run. The TUI's `n` shortcut and "Enter on a member" also load vector neighbors for the selected row.

Large `--limit` values are supported without hitting SQLite's SQL variable limit when loading result metadata. Neighbor search still scores all eligible stored vectors, so larger archives can take longer even with a small result limit.

## Tuning recipes

### My clusters are too greedy
Expand Down
40 changes: 40 additions & 0 deletions internal/store/thread_ids_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package store

import (
"context"
"path/filepath"
"testing"
)

func TestThreadsByIDsBeyondSQLiteParameterLimit(t *testing.T) {
ctx := context.Background()
st, err := Open(ctx, filepath.Join(t.TempDir(), "gitcrawl.db"))
if err != nil {
t.Fatal(err)
}
defer st.Close()
repoID, threadIDs := seedVectorThreads(t, ctx, st)
otherRepoID, err := st.UpsertRepository(ctx, Repository{Owner: "fixture", Name: "other", FullName: "fixture/other"})
if err != nil {
t.Fatal(err)
}
otherID, err := st.UpsertThread(ctx, Thread{RepoID: otherRepoID, GitHubID: "other", Number: 1, Kind: "issue", State: "open", Title: "other repository", LabelsJSON: "[]", AssigneesJSON: "[]", RawJSON: "{}"})
if err != nil {
t.Fatal(err)
}
ids := make([]int64, 32768)
for i := range ids {
ids[i] = int64(i + 100000)
}
ids[0] = threadIDs[0]
ids[len(ids)/2] = otherID
ids[len(ids)-2] = threadIDs[0]
ids[len(ids)-1] = threadIDs[1]
threads, err := st.ThreadsByIDs(ctx, repoID, ids)
if err != nil {
t.Fatalf("large thread lookup: %v", err)
}
if len(threads) != 2 || threads[threadIDs[0]].Number != 301 || threads[threadIDs[1]].Number != 302 {
t.Fatalf("expected only the two requested repository threads, got %+v", threads)
}
}
13 changes: 4 additions & 9 deletions internal/store/vectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"errors"
"fmt"
"math"
"strings"
"unicode"
)

Expand Down Expand Up @@ -138,17 +137,13 @@ func (s *Store) ThreadsByIDs(ctx context.Context, repoID int64, ids []int64) (ma
if len(ids) == 0 {
return map[int64]Thread{}, nil
}
placeholders := make([]string, 0, len(ids))
args := []any{repoID}
for _, id := range ids {
placeholders = append(placeholders, "?")
args = append(args, id)
}
// Integer slices always marshal successfully; one JSON parameter avoids SQLite's bind limit.
idJSON, _ := json.Marshal(ids)
rows, err := s.db.QueryContext(ctx, `
select `+s.threadSelectColumns(ctx, "")+`
from threads
where repo_id = ? and id in (`+strings.Join(placeholders, ",")+`)
`, args...)
where repo_id = ? and id in (select value from json_each(?))
`, repoID, string(idJSON))
if err != nil {
return nil, fmt.Errorf("select threads by id: %w", err)
}
Expand Down
Loading