MCPcopy Index your code
hub / github.com/arunsupe/semantic-grep

github.com/arunsupe/semantic-grep @v1.0.0

Chat with this repo
repository ↗ · DeepWiki ↗ · release v1.0.0 ↗ · + Follow
11 symbols 21 edges 1 files 0 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

sgrep - Semantic Grep

sgrep is a command-line tool that performs semantic searches on text input using word embeddings. It's designed to find semantically similar content based on a given query, going beyond simple string matching.

Features

  • Semantic search using Word2Vec embeddings
  • Configurable similarity threshold
  • Adjustable window size for context
  • Color-coded output based on similarity score
  • Supports configuration via JSON file and command-line arguments

Requirements

  • A Word2Vec model in binary format.
  • download-model.sh is a simple helper script that will download the small word2vec model hosted by eyaler and save it in models/googlenews-slim/ directory
  • Alternatively, you can download and unzip the .bin file locally and update the config.json.

    • Google's Word2Vec: from https://github.com/mmihaltz/word2vec-GoogleNews-vectors
    • A slim version: GoogleNews-vectors-negative300-SLIM.bin.gz model from https://github.com/eyaler/word2vec-slim/

Note: There are no external dependenceis; uses just the stdlib (and the model)

Installation

  • clone the repo
  • run go build -o bin/sgrep
  • run bash download-model.sh # to download the word2vec model

Usage

 curl -s 'https://gutenberg.ca/ebooks/hemingwaye-oldmanandthesea/hemingwaye-oldmanandthesea-00-t.txt' | bin/sgrep --similarity_threshold=0.50 --window=100 --query='promised fish' 
 ```
- run `bin/sgrep` to see commandline flags

## Configuration
sgrep can be configured using a JSON file. By default, it looks for `config.json` in the current directory. You can specify a different configuration file using the `-config` flag.

Example `config.json`:

```json
{
    "model_path": "models/googlenews-slim/GoogleNews-vectors-negative300-SLIM.bin",
    "similarity_threshold": 0.3,
    "window": 50
}

Output

The output includes:

The similarity score for each matching segment
The matching text, color-coded based on similarity (red for lowest, magenta for highest)

License

This project is distributed under the MIT License (refer to LICENSE file for details).

Disclaimer

The provided model might not capture all semantic nuances and may require adjustments based on your specific use case. Consider exploring other models or training your own model for better accuracy.

Core symbols most depended-on inside this repo

toVector
called by 2
sgrep.go
loadConfig
called by 1
sgrep.go
loadWord2VecModel
called by 1
sgrep.go
getVectorEmbedding
called by 1
sgrep.go
processTokenStream
called by 1
sgrep.go
calculateSimilarity
called by 1
sgrep.go
countPunctuations
called by 1
sgrep.go
colorText
called by 1
sgrep.go

Shape

Function 9
Struct 2

Languages

Go100%

Modules by API surface

sgrep.go11 symbols

For agents

$ claude mcp add semantic-grep \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page