sgrep

Library API

Embed semantic code indexing and search in a Go program.

Install the Go module:

go get github.com/XiaoConstantine/sgrep@latest

The root package exposes a small semantic code-search client:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/XiaoConstantine/sgrep"
)

func main() {
	ctx := context.Background()

	client, err := sgrep.New("/path/to/codebase")
	if err != nil {
		log.Fatal(err)
	}
	defer client.Close()

	if err := client.Index(ctx); err != nil {
		log.Fatal(err)
	}

	results, err := client.Search(ctx, "authentication logic", 10)
	if err != nil {
		log.Fatal(err)
	}

	for _, result := range results {
		fmt.Printf("%s:%d-%d (score: %.2f)\n",
			result.FilePath, result.StartLine, result.EndLine, result.Score)
	}
}

SearchWithThreshold exposes the cosine-distance cutoff, and Watch blocks while incrementally indexing until its context is cancelled.

For deeper control, use the packages under pkg/:

PackageResponsibility
pkg/indexRepository indexing and file watching
pkg/searchRetrieval, fusion, caching, ColBERT, and reranking
pkg/embedLocal embedding requests and server selection
pkg/storeSQL metadata and vector artifacts
pkg/chunkAST-aware and token-aware source chunking
pkg/convConversation parsing, indexing, retrieval, and actions

The CLI is the stable user-facing integration surface. Consumers of pkg/ should expect a lower-level API that can evolve with the storage and retrieval implementation.