---
title: "Finding relationships in your data with embeddings"
description: "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."
url: "https://swe.quest/articles/finding-relationships-in-your-data-with-embeddings-269cb25fce48621d"
canonical: "https://incident.io/blog/finding-relationships-in-your-data-with-embeddings"
source: "incident.io"
published: "2024-01-19"
difficulty: "medium"
kind: "Case study"
reading_minutes: 14
tags: ["vector-search","postgres","llms","product-engineering","incident-response"]
---

# Finding relationships in your data with embeddings

A post on [incident.io](https://swe.quest/sources/incident-io.md), published 2024-01-19, 14 min read, Case study. Original: [https://incident.io/blog/finding-relationships-in-your-data-with-embeddings](https://incident.io/blog/finding-relationships-in-your-data-with-embeddings)

## Summary

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.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [Vector search](https://swe.quest/tags/vector-search.md) (Data & databases)
- [PostgreSQL](https://swe.quest/tags/postgres.md) (Data & databases)
- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Product engineering](https://swe.quest/tags/product-engineering.md) (Engineering organization)
- [Incidents & postmortems](https://swe.quest/tags/incident-response.md) (Reliability & operations)

## Prerequisites

- Postgres basics ([easy posts on PostgreSQL](https://swe.quest/tags/postgres.md?difficulty=easy))
- LLM API usage ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- vector similarity concepts

## Keywords

pgvector, HNSW, IVFFLAT, OpenAI, text-embedding-ada-002, cosine similarity, k-means, incident.io

## Related posts

- [Using AI to detect similar issues](https://swe.quest/articles/using-ai-to-detect-similar-issues-df2d1445fbbe6dc8.md): Linear · 2023-11-29 · Medium · 5 min read · Vector search, PostgreSQL, Search, LLMs, Product engineering
  Linear detects duplicate and related issues by embedding issue text with an LLM and running cosine similarity search.
- [Semantic search using OpenAI, pg\_embedding and Neon](https://swe.quest/articles/semantic-search-using-openai-pg-embedding-and-neon-aeafbc27d93ca728.md): Neon · 2023-08-25 · Medium · 9 min read · Vector search, PostgreSQL, LLMs, Serverless, TypeScript
  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.
- [Storing OpenAI embeddings in Postgres with pgvector](https://swe.quest/articles/storing-openai-embeddings-in-postgres-with-pgvector-19a5d03614f86fc6.md): Supabase · 2023-02-06 · Medium · 11 min read · Vector search, PostgreSQL, RAG & retrieval, LLMs
  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.
- [20x faster than pgvector: introducing pg\_embedding extension for vector search in Postgres and LangChain](https://swe.quest/articles/20x-faster-than-pgvector-introducing-pg-embedding-extension-for-vector-search-058737fc9388f495.md): Neon · 2023-07-11 · Medium · 7 min read · Vector search, PostgreSQL, Performance engineering
  pg\_embedding brought HNSW graph-based approximate nearest neighbor indexing to Postgres.
- [Getting Started With Embeddings](https://swe.quest/articles/getting-started-with-embeddings-f83c278b13779a68.md): Hugging Face · 2022-06-23 · Medium · 11 min read · Search, Machine learning, Python, Vector search
  Embeddings turn text or images into fixed-length vectors that capture meaning, so semantic similarity becomes a distance calculation.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
