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.
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
- Go 1.24+
- Ollama running locally on
http://localhost:11434 - the
nomic-embed-textmodel installed in Ollama
Example setup:
ollama pull nomic-embed-text
ollama servego build -o sgrep .Search a file:
./sgrep "memory error" ./test.txtSearch stdin:
cat ./test.txt | ./sgrep "wifi stability"Index a file in advance:
./sgrep index ./test.txtAdjust the similarity threshold:
./sgrep --threshold 0.7 "docker failure" ./test.txtSearches for the lines most semantically similar to phrase.
- with
[file],sgrepreads from the file and reuses cached embeddings when possible - without
[file],sgrepreads from stdin
Embeds and caches a file without running a search.
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.
sgrepcurrently 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