Database / pgvector basics Interview Questions
What are vector embeddings and why are they central to pgvector's use?
A vector embedding is a list of floating-point numbers produced by a machine learning model that encodes the semantic meaning of some input data. The defining property is that semantically similar inputs produce numerically similar vectors - meaning you can measure the 'closeness' of two concepts by computing the distance between their vectors.
| Input data | Model | Dimensions | Application |
|---|---|---|---|
| Text (sentences, paragraphs) | OpenAI text-embedding-3-small | 1,536 | Semantic search, RAG |
| Text | OpenAI text-embedding-3-large | 3,072 | Higher-quality RAG |
| Text | Google text-embedding-004 | 768 | Google AI search |
| Images | CLIP, ResNet | 512-2048 | Image similarity search |
| User behaviour | Collaborative filtering model | Varies | Recommendations |
# Example: generating embeddings with OpenAI from openai import OpenAI client = OpenAI() texts = [ "I love programming in Python.", "Python is my favourite coding language.", "I enjoy outdoor hiking on weekends.", ] response = client.embeddings.create( model="text-embedding-3-small", input=texts, ) embeddings = [item.embedding for item in response.data] # embeddings[0] and embeddings[1] will be numerically close # embeddings[0] and embeddings[2] will be numerically far apart print(f"Dimension: {len(embeddings[0])}") # 1536 print(f"Type: {type(embeddings[0][0])}") # float
Embeddings make semantic search possible: instead of matching keywords, you match meaning. A user querying 'something warm for high-altitude hiking' can find a product described as 'insulated mountain jacket' even though not a single word overlaps - because both phrases produce similar vectors.
More Related questions...