0Pricing
Vector Databases: Pinecone, Weaviate & pgvector · 강의

PostgreSQL에 벡터 저장하기

벡터 열이 있는 테이블을 만들고 임베딩 데이터를 PostgreSQL 데이터베이스에 직접 삽입하는 방법을 배웁니다.

PostgreSQL에 벡터 저장하기은(는) CoddyKit의 무료 Vector Databases: Pinecone, Weaviate & pgvector 강의입니다. 이것은 4개 중 2번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Vector Databases: Pinecone, Weaviate & pgvector 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Vector Databases: Pinecone, Weaviate & pgvector 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

Storing Vectors in PostgreSQL

Welcome back! In the previous lesson, we set up pgvector. Now, let's get practical and learn how to store actual vector embeddings in your PostgreSQL database.

This lesson covers creating tables with vector columns and inserting embedding data.

PostgreSQL Tables Reminder

Before storing vectors, let's quickly recall how tables work in PostgreSQL. You use the CREATE TABLE statement to define your table's structure, including column names and their data types.

With pgvector installed, we gain a new, powerful data type!

The `vector` Data Type

The core of storing embeddings with pgvector is the vector data type. When you define a column as vector(N), N represents the dimension of your embeddings.

  • vector(3): Stores 3-dimensional vectors.
  • vector(1536): Stores 1536-dimensional vectors (common for OpenAI embeddings).

It's crucial that N matches the dimension of the embeddings you're working with.

Creating a Table with Vectors

To store embeddings, you'll create a table just like any other, but specify one or more columns as type vector(N).

Here's an example creating a simple table to hold items and their 3-dimensional embeddings:

CREATE TABLE items (
  id SERIAL PRIMARY KEY,
  embedding vector(3)
);

Understanding Vector Dimensions

The number N in vector(N) is vital. It must precisely match the number of values (dimensions) in your actual embedding vectors. If your embedding model produces 768-dimensional vectors, your column must be vector(768).

Mismatched dimensions will result in errors when inserting data. Always check your embedding model's output dimension!

Inserting Single Vector Data

Once your table is set up, you can insert vector data using the standard INSERT INTO SQL command. Vector values are provided as a string representation of a list of numbers, e.g., '[1.2, 3.4, 5.6]'.

INSERT INTO items (embedding)
VALUES ('[1.0, 2.0, 3.0]');

Inserting Multiple Vectors

You can insert multiple vectors into your table efficiently by providing multiple sets of values in a single INSERT INTO statement.

Each set of values corresponds to a new row in your table.

INSERT INTO items (embedding) VALUES
  ('[4.0, 5.0, 6.0]'),
  ('[7.0, 8.0, 9.0]');

Storing Vectors with Metadata

In real-world applications, you'll almost always store additional information (metadata) alongside your vectors. This could be text content, a user ID, a timestamp, or any other relevant data.

Just add more columns to your table definition:

CREATE TABLE documents (
  id SERIAL PRIMARY KEY,
  content TEXT,
  category VARCHAR(50),
  embedding vector(4)
);

Inserting Vectors & Metadata

When inserting data into a table with metadata, simply provide values for all the columns you wish to populate. Make sure the order of values matches the order of columns specified in your INSERT INTO statement.

INSERT INTO documents (content, category, embedding) VALUES
  ('The quick brown fox.', 'animal', '[0.1, 0.2, 0.3, 0.4]');

Quick Check: Table Creation

Which of the following SQL statements correctly creates a table named products with an auto-incrementing primary key id and a vector column product_embedding of 1536 dimensions?

Recap: Storing Your Vectors

Great job! You've learned the fundamental steps to store vector embeddings in PostgreSQL using pgvector:

  • Defining vector columns with vector(N), ensuring N matches your embedding dimensions.
  • Creating tables with both vector and metadata columns.
  • Inserting single and multiple vector data points, along with their associated metadata.

Next, we'll explore how to query this data to find similar vectors!

자주 묻는 질문

“PostgreSQL에 벡터 저장하기” 강의는 무료인가요?

네 — “PostgreSQL에 벡터 저장하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Vector Databases: Pinecone, Weaviate & pgvector 강의 전체를 잠금 해제할 수 있습니다. Vector Databases: Pinecone, Weaviate & pgvector 강의에는 총 4개의 강의가 포함되어 있습니다.

“PostgreSQL에 벡터 저장하기”에서 뭘 배우나요?

벡터 열이 있는 테이블을 만들고 임베딩 데이터를 PostgreSQL 데이터베이스에 직접 삽입하는 방법을 배웁니다. 브라우저에서 직접 실행하는 실습 코드로 Vector Databases: Pinecone, Weaviate & pgvector을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Vector Databases: Pinecone, Weaviate & pgvector을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Vector Databases: Pinecone, Weaviate & pgvector은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 2번째 강의입니다.

“PostgreSQL에 벡터 저장하기” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Vector Databases: Pinecone, Weaviate & pgvector 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Vector Databases: Pinecone, Weaviate & pgvector 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. pgvector 확장 기능 설정하기
  2. PostgreSQL에 벡터 저장하기
  3. 유사도 질의 실행하기
  4. pgvector에서 거리 메트릭 선택하기
← Vector Databases: Pinecone, Weaviate & pgvector(으)로 돌아가기