Django & PGVector - Vector-Based Search in Django with PGVector & PostgreSQL
Описание
In this video, we look at connecting Django to Postgres and PGVector, and how to use a VectorField on our Django models to connect them with an underlying column of type vector.
We'll create a small proof-of-concept Django app where a user can submit some text, which is embedded using OpenAI, and then we search the database to find the "most similar" documents using PGVector and its distance metrics - L2Distance, CosineDistance, etc.
We'll also see how to add vectors to the database with Django, and how to use the inspectdb management command to integrate a Django app with an existing database.
☕️ ??? ?? ? ??????:
To support the channel and encourage new videos, please consider buying me a coffee here:
https://ko-fi.com/bugbytes
? ????????:
00:00 Intro
01:20 Setup pgvector with Docker
02:48 Connect Django to Postgres database container
04:43 Using inspectdb management command to auto-generate models for existing database
06:52 Adding pgvector VectorField to Django Model
10:10 Adding documents and embeddings to template
14:27 Embedding text with openai Embedding model
20:35 Querying the database with pgvector L2Distance metric
26:33 Inserting vector data with Django and pgvector
29:55 Summary and use-cases
?????? ?????:
? Blog: https://bugbytes.io/posts/
? Github: https://github.com/bugbytes-io/
? Twitter: https://twitter.com/bugbytesio
? ??????? ??????? ??? ???????????:
pgvector: https://github.com/pgvector/pgvector
Python-pgvector: https://github.com/pgvector/pgvector-python
pgvector Docker image: https://hub.docker.com/r/ankane/pgvector
Django inspectdb command: https://docs.djangoproject.com/en/4.2/howto/legacy-databases/
OpenAI Embeddings API: https://platform.openai.com/docs/guides/embeddings
#python #langchain #datascience #postgresql #django
Рекомендуемые видео

















