Skip to content
radekgrzywaczPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

7 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sgrep

sgrep is a small Go CLI for semantic search over text files and stdin. Instead of exact string matching, it generates embeddings with a locally running Ollama model and returns the most similar lines.

How it works

sgrep:

  • embeds the search query with Ollama
  • embeds each input line
  • computes cosine similarity
  • prints the top 3 matches above a configurable threshold
  • caches file embeddings under the user cache directory for faster repeated searches

Requirements

  • Go 1.24+
  • Ollama running locally on http://localhost:11434
  • the nomic-embed-text model installed in Ollama

Example setup:

ollama pull nomic-embed-text
ollama serve

Build

go build -o sgrep .

Usage

Search a file:

./sgrep "memory error" ./test.txt

Search stdin:

cat ./test.txt | ./sgrep "wifi stability"

Index a file in advance:

./sgrep index ./test.txt

Adjust the similarity threshold:

./sgrep --threshold 0.7 "docker failure" ./test.txt

Commands

sgrep [phrase] [file]

Searches for the lines most semantically similar to phrase.

  • with [file], sgrep reads from the file and reuses cached embeddings when possible
  • without [file], sgrep reads from stdin

sgrep index [file]

Embeds and caches a file without running a search.

Cache behavior

Cached embeddings are stored in the OS user cache directory inside an sgrep subdirectory. The cache key is derived from the file path, and cache validity is checked against the current file content hash.

Notes

  • sgrep currently returns at most 3 matches
  • the default similarity threshold is 0.5
  • the embedding model is currently hardcoded to nomic-embed-text
  • if Ollama is not running, requests will fail with a network error

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages