dwyl / learn-postgresql

🐘 Learn how to use PostgreSQL and Structured Query Language (SQL) to store and query your relational data. 🔍
211 stars 23 forks source link

PGVECTOR-ELIXIR extension: example with the classification of data using OpenAI #103

Open ndrean opened 1 year ago

ndrean commented 1 year ago

1. An example of a usage of pgvector.

We want to classify a dataset using "a certain distance" among the rows. The idea is to send the data to the (rate limited) OpenAI api endpoint, get in return tokens for each row, store as a vector, and then apply a distance sorting query between rows based on this vector field.

Note: the distance operator <=> is also used with PostGIS.

Screenshot 2023-05-09 at 10 09 35

2. pgvector and indexes

Screenshot 2023-05-09 at 16 48 03

A summary of the post above, as found in the post!: pgvectorprovides a comprehensive, performant, and 100% open source database for vector data. As a developer, the key to getting performance from pgvector are:

ndrean commented 1 year ago

3. pgvector-elixir

I want to use pgvector-elixir with Elixir.

❌ I failed miserably to install the extension PGVECTOR with brew install pgvector because I installed Postgres.App, and make doesn't seem to work easily on my brand new M2.

🚀 I installed postgresql@14 via homebrew, then pgvector, and I can CREATE EXTENSION VECTOR;. It is just more annoying than using the Postgres.App.

Screenshot 2023-05-09 at 16 54 53

ndrean commented 1 year ago

Next step, build a repo or Livebook to test this.

ndrean commented 7 months ago

A nice post on pgvector with ML in mind:

Screenshot 2023-11-27 at 14 43 56

and pgvector and HNSW: Screenshot 2023-11-27 at 16 48 02