# Embeddings Are a Good Starting Point for the AI Curious App Developer - Bryant Synced: [[2024_04_18]] 7:05 PM Last Highlighted: [[2024_04_17]] Tags: [[AI]] [[Career Growth]] ![rw-book-cover](https://substackcdn.com/image/fetch/w_1200,h_600,c_fill,f_jpg,q_auto:good,fl_progressive:steep,g_auto/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcb972599-8305-4943-a8e6-689a7f30bae3_1792x1024.png) Really great article summarizing a simple but powerful use case for ai in search results. Much better semantic search of content is powerful Summary: Embeddings are arrays of numbers that compress human knowledge and simplify specialized projects for developers. Postgres with pgvector allows for efficient storage and querying of embeddings, enabling features like similarity search and filtering. By combining embedding search with user interactions, developers can create more sophisticated ranking algorithms for better search results. ## Highlights [[2024_04_17]] [View Highlight](https://read.readwise.io/read/01hvpxq5snfzx3t87hzw6xyyhw) > Vector embeddings work for search and recommendations because they’re good at measuring similarity to arbitrary input. This even works for different spoken languages like French or Japanese. [[2024_04_17]] [View Highlight](https://read.readwise.io/read/01hvpxqday2q6x2mw58yrnvahc) > [Pgvector](https://github.com/pgvector/pgvector/) is a Postgres extension that stores and queries embeddings without adding a new service. It’s powerful because it can combine standard SQL logic with embedding operations [[2024_04_17]] [View Highlight](https://read.readwise.io/read/01hvpxqk845cn6yj5czfbhnfr0) > • Unlike LLMs, working with embeddings feels like regular deterministic code. [[2024_04_17]] [View Highlight](https://read.readwise.io/read/01hvpywammct012hhhadednz7h) > Vector database > We chose [pgvector](https://github.com/pgvector/pgvector)/Postgres, but there are plenty of [other choices](https://lakefs.io/blog/12-vector-databases-2023/), including some for other standard databases like MongoDB. [[2024_04_17]] [View Highlight](https://read.readwise.io/read/01hvpyv72gm2y57z44wm6aydk9) > Embedding string > We embedded strings of key and value pairs for the attributes we thought best described our icons. It doesn’t seem like any of the major players are doing anything crazy here; the significant knobs appear to be whether or not to embed keys or just values and which attributes of your records are relevant. Other examples in OpenAI’s [cookbook](https://cookbook.openai.com/examples/vector_databases/readme) show [other](https://github.com/vercel/examples/blob/main/storage/postgres-pgvector/prisma/seed.ts#L35) [choices](https://github.com/neondatabase/yc-idea-matcher/blob/18eb9dd6ddd14eeeb2167d78088f092ab6882f42/generate-embeddings.ts#L51). [[2024_04_17]] [View Highlight](https://read.readwise.io/read/01hvpyvcvcjvr37se2fkan1q4h) > Distance metric > We used cosine similarity as our distance function because that’s what OpenAI [recommends](https://platform.openai.com/docs/guides/embeddings/which-distance-function-should-i-use) for their embeddings. Other embeddings may be optimized for different strategies. Pgvector [supports](https://github.com/pgvector/pgvector?tab=readme-ov-file#distances) l2 distance, inner product, and cosine distance [[2024_04_17]] [View Highlight](https://read.readwise.io/read/01hvpyvv5m6566gx6xfk1vskhz) > Search Size > In these examples, we limited our queries to the top 50 results. You can also limit your search to be above or below a certain distance threshold. That doesn’t seem super reliable. Relative distances seem more meaningful than discrete amounts. If you’re set on using a threshold, I’d recommend keeping it pretty wide, like 0.1 or 0.05, and using it with a limit. You may get some mileage using a wide range to avoid returning irrelevant long-tail results.