January 1, 2026
Highways, not haystacks
Implementing HNSW (Hierarchical Navigable Small World) Vector Search in PHP
PHP takes the fast lane to finding stuff, and commenters are loving it
TLDR: A developer built a layered “shortcut” search in PHP that finds answers fast without checking everything. Comments celebrate the clarity and bold language choice, praising high-level readability and dunking on copy‑paste Python, while skeptics quietly wonder if Rust or Python should’ve been used.
PHP did what now? A dev just wired a “highway map” for finding stuff fast, using HNSW—think zooming from highways to side streets—to turn hour-long hunts into milliseconds. The author explains it in plain city-map terms and even drops real code, then casually says, “Yeah, it’s in PHP.” Cue the comment fireworks.
OP jumps in: “PHP isn’t the typical choice,” but with modern Just-In-Time (JIT) speed in PHP 8 and a neat project called Vektor, it’s a practical drop-in for big PHP apps. One fan cheers that it “makes perfect sense in a high-level language”, backing readability over ritual hardware worship. Another applauds it for not being yet another copy‑paste Python job, calling the post thoughtful and original.
The strongest opinions? That clarity beats hype, and PHP can absolutely play in the “smart search” arena. The mild drama: purists expected Rust or Python, but the comments skew supportive, turning the usual language wars into a wholesome “use what works” moment.
Humor landed hard: jokes about librarians speedrunning shelves, “PHP in this economy?” memes, and highway‑map gifs. The vibe: unexpectedly joyful, a little rebellious, and very “ship it.” If HNSW is the road system, this post was the carpool lane.
Key Points
- •Linear cosine-similarity search is O(N) and slow at large scale.
- •HNSW uses layered graphs, with sparse long connections at higher levels and dense short connections at lower levels.
- •The PHP implementation (from the Vektor project) starts at a high-level entry point and descends levels, choosing closer neighbors via cosine similarity.
- •When no closer neighbor is found at a level, the search descends to the next level, culminating at Level 0.
- •Parameter M controls maximum node connections, trading off connectivity against memory; ef is noted as an important search parameter.