This documentation page is also available as an interactive notebook. You can launch the notebook in
Kaggle or Colab, or download it for use with an IDE or local Jupyter installation, by clicking one of the
above links.
Generate vector embeddings for text data to enable semantic search and
similarity matching.
Problem
You need to convert text into vector embeddings for:
- Semantic search (find similar documents)
- RAG pipelines (retrieve relevant context)
- Clustering and classification
Solution
What’s in this recipe:
- Generate embeddings with OpenAI’s models
- Store embeddings as computed columns
- Use embeddings for similarity queries
You add an embedding column that automatically generates vectors for new
rows. The embeddings are cached and only recomputed when the source text
changes.
Setup
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘embed_demo’.
<pixeltable.catalog.dir.Dir at 0x14ee4fcd0>
Create table with embedding column
Created table ‘documents’.
Added 0 column values with 0 errors.
No rows affected.
Insert documents
Inserting rows into `documents`: 5 rows [00:00, 553.22 rows/s]
Inserted 5 rows with 0 errors.
5 rows inserted, 15 values computed.
Query by similarity
Find documents similar to a query by creating an embedding index:
Explanation
OpenAI embedding models:
Similarity metrics:
Key benefits of computed embedding columns:
- Embeddings are generated automatically on insert
- Results are cached—no re-computation on subsequent queries
- Index enables fast similarity search at scale
See also