Skip to content

Instantly share code, notes, and snippets.

@AstraBert
AstraBert / sparse_inference_nq.py
Created November 3, 2026 10:48
Encodes N documents from the NQ corpus (BeIR) with a sparse neural encoder (tested with ibm-granite/granite-embedding-30m-sparse and Linkup-Platform/linkup-sparseup-embed-v1). Better to run on GPU (granite does 300 docs/s on Mac Silicon GPUs, sparseup does ~30 docs/s)
#!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "sentence-transformers>=5.1,<6",
# "huggingface-hub",
# "pyarrow==26.0.0",
# ]
#
@AstraBert
AstraBert / query_cut_bench_slideon.py
Created November 3, 2026 10:46
Benchmark script for sparse vectors from SlideOn datasets and other generated datasets that adopt the same format. Essentially the same as query_cut_bench,py evaluation-wise
#!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "httpx==0.28.1",
# "huggingface-hub==2.4.0",
# "numpy==2.5.4",
# "pyarrow==26.0.0",
# "scipy==1.18.1",
@AstraBert
AstraBert / query_cut_bench.py
Created November 2, 2026 16:26
Code used to benchmark latency and retrieval quality of approximate sparse search (introducing a `query_cut` parameter that only considers the top dimensions for a query, selected by absolute weight)
#!/usr/bin/env -S uv run --script
#
# /// script
# requires-python = ">=3.12"
# dependencies = [
# "httpx==0.28.1",
# "ijson==3.3.0",
# "numpy==2.5.4",
# "scipy==1.18.1",
# ]
@AstraBert
AstraBert / sqlengine.py
Last active December 20, 2025 13:40
Solution to SQL engine coding problem
import re
from typing import Any
PARSER = re.compile(r'^SELECT (.*) FROM [a-z]+(?: WHERE (.*?))?(?: ORDER BY (.*?))?(?: LIMIT (\d+))?$')
# Example
# print(PARSER.match("SELECT a, d FROM library WHERE b = 1 AND d = 3 ORDER BY c, d").groups())
# This prints: ('a, d', 'b = 1 AND d = 3', 'c, d')
@AstraBert
AstraBert / workflows_and_memory.ipynb
Created September 17, 2025 15:51
workflows_and_memory.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AstraBert
AstraBert / sentrev_practical_showcase.ipynb
Created December 5, 2024 02:23
SenTrEv_Practical_Showcase.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@AstraBert
AstraBert / filter_vcfs.ipynb
Last active May 10, 2024 23:51
filter_vcfs.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.