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.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
