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.
Create lookup functions that query tables by key—for customer records,
product catalogs, or financial data.
Problem
You have structured data—customer records, product catalogs, financial
data—and need to look up rows by key values. Common scenarios:
Solution
What’s in this recipe:
- Create lookup functions from tables with
retrieval_udf
- Query by single or multiple keys
- Use lookups in computed columns for data enrichment
Use pxt.retrieval_udf(table) to automatically create a function that
queries the table by its columns.
Setup
Connected to Pixeltable database at: postgresql+psycopg://postgres:@/pixeltable?host=/Users/pjlb/.pixeltable/pgdata
Created directory ‘lookup_demo’.
<pixeltable.catalog.dir.Dir at 0x143224e50>
Create a product catalog table
Created table ‘products’.
Inserting rows into `products`: 5 rows [00:00, 502.31 rows/s]
Inserted 5 rows with 0 errors.
Create a lookup function with retrieval_udf
Look up by category (multiple results)
Use lookups for data enrichment
Created table ‘orders’.
Inserting rows into `orders`: 3 rows [00:00, 1186.28 rows/s]
Inserted 3 rows with 0 errors.
3 rows inserted, 6 values computed.
Added 3 column values with 0 errors.
Explanation
retrieval_udf parameters:
Use cases:
Tips:
- Use
limit=1 for unique key lookups
- Specify only needed columns in
parameters for cleaner APIs
- Add descriptions for LLM tool integration
See also