Glance
Code at a glance. Highlight important parts of the code using embeddings and PageRank.
Install / Use
/learn @novoselrok/GlanceREADME
Glance
Code at a glance. Highlight important parts of the code using embeddings and PageRank.
Preview

Usage
Install dependencies (Python 3.x):
pip install -r requirements.txt
Print out top 10 important "windows" of code:
# From a local file
python glance.py --model=intfloat/e5-small-v2 --file="file.go" --top=10
# From a Sourcegraph file
export SOURCEGRAPH_API_TOKEN=XYZ
python glance.py --model=intfloat/e5-small-v2 --file="https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/internal/embeddings/embed/embed.go" --top=10
Run the web app:
export SOURCEGRAPH_API_TOKEN=XYZ
export GLANCE_MODEL_PATH=intfloat/e5-small-v2
flask --app app run --port 5001
And then navigate to: http://127.0.0.1:5001/?file=https://sourcegraph.com/github.com/sourcegraph/sourcegraph/-/blob/internal/embeddings/embed/embed.go
How does it work?
- We split the code into overlapping windows of a certain size (e.g., 5 lines).
- For each window, we embed the code using a pre-trained code embedding model (e.g.
intfloat/e5-small-v2). This gives us a dense vector representation of the code window. - We create an adjecency matrix by calculating the cosine similarity between all pairs of embeddings. The adjecency matrix represents a weighted undirected graph.
- We run PageRank on the adjecency matrix to calculate the "importance" score of each code window.
Intuitively, code windows that are similar to many other important code windows will have a higher PageRank score and thus higher importance.
Future Improvements
- Focusing on line windows is not ideal. Instead, a better approach would be to parse the code and identify syntactic structures like functions and classes.
- Cross-file and repository support. Embed an entire repo, and run PageRank across the repo embeddings. Would probably have to a more performant PageRank implementation.
Thanks
Shout-out to Matt Neary's Salience project which inspired Glance.
Related Skills
node-connect
348.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.1kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
348.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
348.5kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
