semantic-index

command
v0.6.20 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 17 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

semantic-index

semantic-index is a self-contained, zero-cgo (CGO_ENABLED=0) macOS hybrid semantic and metadata search example combining:

  • github.com/tmc/apple/corespotlight (CSSearchableIndex, CSSearchableItem, CSSearchableItemAttributeSet) for indexing document metadata into a scoped Spotlight domain with automatic cleanup on exit.
  • github.com/tmc/apple/naturallanguage (NLTokenizer, NLEmbedding) for on-device tokenization and dense embeddings, probing both sentence and word embedding assets on the host and falling back deterministically to hashed n-gram TF-IDF if neither asset is installed.
  • Pure-Go mean-centered cosine similarity over a flat contiguous float32 embedding matrix fused with Okapi BM25 lexical scoring and exponential recency decay.

Running

Run the full self-contained demo (30-document Apple Silicon systems corpus, scoped CoreSpotlight indexing + cleanup, zero-keyword-overlap recall evaluation, and latency benchmark):

CGO_ENABLED=0 go run ./examples/corespotlight/semantic-index

Run an ad-hoc hybrid query (optionally filtered by category metadata):

CGO_ENABLED=0 go run ./examples/corespotlight/semantic-index -query "lock-free audio render" -top 5
CGO_ENABLED=0 go run ./examples/corespotlight/semantic-index -query "shader cache" -category metal

Measured output

Measured on Apple M4 Max, macOS 26.6.2 (Build 25G83) with CGO_ENABLED=0 go run ./examples/corespotlight/semantic-index:

semantic-index (zero-cgo CoreSpotlight + NaturalLanguage hybrid search)
embedder:  NLEmbedding(word-avg) lang=en dim=300 vocab=57171 rev=1 (sentence_asset=true word_asset=true) (loaded in 105.009ms)
corpus:    30 documents, 300-dim unit vectors (embedded+indexed in 94.101ms)
spotlight: indexed 30 CSSearchableItem records in domain dev.tmc.apple.examples.corespotlight.semantic-index.86976 (41.323ms)

zero-keyword-overlap semantic recall (8 queries):
  "stopping sound distortion and stereo playback dropouts" overlap=0  bm25=miss sem=#3   hyb=#3   top1=avaudioengine-spatial (cos=0.375)
  "keeping a secret asymmetric password locked behind fingerprint authentication" overlap=0  bm25=miss sem=#1   hyb=#1   top1=secure-enclave-keys (cos=0.365)
  "instantly replicating massive documents on hard drives saving capacity" overlap=0  bm25=miss sem=#1   hyb=#2   top1=videotoolbox-hevc-encode (cos=0.091)
  "fixing dropped cellular packets on concurrent internet socket connections" overlap=0  bm25=miss sem=#3   hyb=#2   top1=rdma-thunderbolt-fabric (cos=0.300)
  "shrinking cinema film footage into smaller broadcast clips" overlap=0  bm25=miss sem=miss hyb=miss top1=screencapturekit-frames (cos=0.241)
  "saving laptop electricity by moving slow maintenance jobs to quieter processors" overlap=0  bm25=miss sem=#1   hyb=#1   top1=dispatch-gcd-queues (cos=0.217)
  "reducing slow boot latency by preloading graphics instructions" overlap=0  bm25=miss sem=miss hyb=miss top1=rdma-thunderbolt-fabric (cos=0.185)
  "running debian unix operating systems inside isolated virtual machines" overlap=0  bm25=miss sem=#1   hyb=#3   top1=apfs-mmap-weights (cos=0.139)

recall summary (8 zero-overlap queries):
  BM25-only:     Top-1=0/8  Top-3=0/8
  Semantic-only: Top-1=4/8  Top-3=6/8
  Hybrid fusion: Top-1=2/8  Top-3=6/8

hybrid search example (query="zero copy tensor memory sharing on apple silicon"):
  1. ane-iosurface-tensors        [ane] score=0.481 (sem=0.395 bm25=8.61 rec=0.93) — Zero-Copy IOSurface Tensor Exchange for the Neural Engine
  2. metal-unified-memory         [metal] score=0.463 (sem=0.363 bm25=11.19 rec=0.72) — Zero-Copy Unified Memory Residency on Apple Silicon
  3. metal-mpsgraph-fusion        [metal] score=0.413 (sem=0.362 bm25=4.41 rec=0.85) — Operator Fusion in MPSGraph Tensor Pipelines

latency benchmark (30 docs, 300-dim):
  vector+BM25 scan (1000 iters):       18.43 µs/query
  end-to-end hybrid (10 iters):      121.72 µs/query
spotlight: cleaned up domain dev.tmc.apple.examples.corespotlight.semantic-index.86976 in 711.136ms

Verification

CGO_ENABLED=0 go vet ./examples/corespotlight/semantic-index
CGO_ENABLED=0 go test -v -count=1 ./examples/corespotlight/semantic-index
CGO_ENABLED=0 go run ./examples/corespotlight/semantic-index

Documentation

Rendered for darwin/amd64

Overview

Command semantic-index demonstrates local hybrid semantic + metadata search on macOS without cgo, combining CoreSpotlight (CSSearchableIndex, CSSearchableItem, CSSearchableItemAttributeSet) with NaturalLanguage (NLTokenizer, NLEmbedding) and fast pure-Go cosine similarity + Okapi BM25 fusion.

Usage:

CGO_ENABLED=0 go run ./examples/corespotlight/semantic-index
CGO_ENABLED=0 go run ./examples/corespotlight/semantic-index -query "lock-free audio render" -top 5
CGO_ENABLED=0 go run ./examples/corespotlight/semantic-index -query "shader cache" -category metal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL