Skip to content

In development. Expect rough edges and changes. The source code is not public yet.

incident.io 14 min read Case study mediumAdept

Finding relationships in your data with embeddings

incident.io built a related-incidents feature by embedding a plain-text representation of each incident with OpenAI's text-embedding-ada-002 and ranking matches by cosine similarity. Prompt construction mattered most. Leaving out noisy fields such as timestamps and IDs, sorting values consistently, flattening rich text, labelling fields and replacing newlines all improved consistency, and k-means clustering was used to gauge prompt quality. In production the embeddings live in Postgres via pgvector with an HNSW index, keyed by model and prompt version so backfills can run without gaps in suggestions. In-progress incidents are re-embedded periodically once they hold enough content to give useful matches.

Assumes: Postgres basicsLLM API usagevector similarity concepts

Related posts

  • Using AI to detect similar issues

    Linear mediumAdept

    Linear detects duplicate and related issues by embedding issue text with an LLM and running cosine similarity search. Matches appear in the issue composer, the Triage inbox and support integrations such as Intercom. After trying several dedicated vector databases, the team rejected them for scaling downtime, cost or ops burden and chose PostgreSQL with pgvector on Google Cloud. A Kubernetes-based task runner backfilled embeddings for tens of millions of issues. Unindexed queries took seconds, and indexing at that scale only worked after partitioning the embeddings table by workspace ID into several hundred partitions and indexing each one separately, following pgvector's parameter recommendations.

  • Semantic search using OpenAI, pg_embedding and Neon

    Neon mediumAdept

    A YC idea-matcher app implements semantic search by embedding ~4,400 YCombinator company descriptions with OpenAI's text-embedding-ada-002 (1536 dimensions) and storing them as real[] columns in Neon Postgres via the pg_embedding extension. Queries embed the user's idea and order rows by cosine distance (<=>) to return the top five matches from a Next.js edge function, which is colocated with the database region and uses the Neon serverless driver, Upstash rate limiting and Zod validation. The full ingestion script and API route are shown. Sequential scan is fine for this small dataset, but larger tables need an HNSW index. pg_embedding has since been deprecated in favor of pgvector.

  • Storing OpenAI embeddings in Postgres with pgvector

    Supabase mediumAdept

    pgvector adds a vector data type and distance operators (Euclidean <->, negative inner product <#>, cosine <=>) to Postgres, so OpenAI text-embedding-ada-002 embeddings (1536 dimensions) can be stored and queried for similarity directly in the database. The walkthrough creates a documents table, a match_documents SQL function that filters by a cosine-similarity threshold, and an IVFFlat index sized at roughly 4 * sqrt(rows) lists. It then generates embeddings in JavaScript and builds Deno Edge Functions for semantic search and for retrieval-augmented answers with text-davinci-003, keeping injected context under about 1500 tokens to fit the 4000-token limit.

  • 20x faster than pgvector: introducing pg_embedding extension for vector search in Postgres and LangChain

    Neon mediumAdept

    pg_embedding brought HNSW graph-based approximate nearest neighbor indexing to Postgres. On the GIST-960 dataset (1M 960-dim vectors, k=100, 4 vCPU/16 GB), it ran 5–30x faster than pgvector's IVFFlat at equal recall. IVFFlat needs more probes to raise recall and drifts toward a sequential scan, while HNSW's layered graph gives roughly logarithmic search. HNSW trades higher memory use, slower index builds (driven by efConstruction) and L2-only distance for that speed. Neon has since deprecated pg_embedding in favor of pgvector, which now supports HNSW natively.

  • Getting Started With Embeddings

    Hugging Face mediumAdept

    Embeddings turn text or images into fixed-length vectors that capture meaning, so semantic similarity becomes a distance calculation. A walkthrough builds a small FAQ matcher: it embeds 13 Medicare FAQs into 384-dimensional vectors with sentence-transformers/all-MiniLM-L6-v2 through the Hugging Face Inference API, hosts the vectors as a CSV dataset on the Hub, then embeds a user query and ranks the top 5 FAQs by cosine similarity with util.semantic_search. Practical notes include retrying the first API call while the model loads, and using FAISS via add_faiss_index as an alternative search path.

The quest for software engineering knowledge.

Look:
Layout: