Vector Databases: Pinecone, Weaviate & pgvector · 강의

속도를 위한 IVFFlat 색인

더 빠른 질의를 위해 pgvector에 IVFFlat 색인을 구현하여 근사 최근접 이웃 검색을 가속합니다.

레슨 1/411개 단계

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

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

Faster Searches with IVFFlat

Welcome to optimizing pgvector performance! For small datasets, a simple vector similarity query might be fast enough. But as your data grows, brute-force search becomes too slow.

This lesson introduces IVFFlat indexing, a powerful technique to accelerate Approximate Nearest Neighbor (ANN) searches in pgvector.

Why Vector Indexes are Key

Imagine searching for the closest person to you in a massive crowd. Without any organization, you'd have to check every single person.

Similarly, without an index, pgvector has to compare your query vector to every single vector in your table. This is called a brute-force search, and it's inefficient for large datasets.

  • Indexes organize data.
  • They make lookups much faster.
  • Crucial for scalable vector search.

IVFFlat: The Core Idea

IVFFlat (Inverted File Index with Flat quantizer) is an ANN indexing algorithm. Its core idea is to group similar vectors into 'lists' or 'clusters'.

Think of it like sorting books by genre before looking for a specific title. You first pick the right genre, then search within that smaller section.

How IVFFlat Works: Two Steps

When you query an IVFFlat index, it performs a two-step process:

  1. Find nearest lists: It quickly identifies a few (or more) clusters that are closest to your query vector.
  2. Search within lists: It then only searches for nearest neighbors within those selected clusters, ignoring the rest of the dataset.

This significantly reduces the number of comparisons needed, speeding up your queries.

The `lists` Parameter Explained

When creating an IVFFlat index, the most important parameter is lists. This defines how many clusters (or partitions) your data will be divided into.

  • More lists: Each cluster has fewer vectors. This can lead to faster searches (less data to scan per cluster).
  • Fewer lists: Each cluster has more vectors. Searches might be slower, but you're less likely to miss true nearest neighbors.

It's a trade-off between search speed and recall (how many of the true nearest neighbors you actually find).

Prepare Your Vector Table

Before creating an index, you need a table with a vector column. If you haven't already, ensure the vector extension is enabled.

Here's a quick setup for a table with 3-dimensional vectors:

CREATE EXTENSION IF NOT EXISTS vector;

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

INSERT INTO items (embedding) VALUES
('[1,2,3]'),
('[1.1,2.1,3.1]'),
('[4,5,6]'),
('[4.1,5.1,6.1]'),
('[7,8,9]'),
('[7.1,8.1,9.1]');

Creating an IVFFlat Index

Now, let's create an IVFFlat index on our embedding column. We'll specify the vector_l2_ops operator class for L2 distance (Euclidean distance), and set the lists parameter.

A good starting point for lists is rows / 1000 for up to 1M rows, or sqrt(rows) for larger datasets.

CREATE INDEX ON items USING ivfflat (embedding vector_l2_ops) WITH (lists = 4);

Querying with the Index

Once the IVFFlat index is created, your standard similarity queries will automatically benefit from it! pgvector will use the index to find approximate nearest neighbors much faster.

Let's find the 3 closest items to [1,2,3]:

SELECT id, embedding <-> '[1,2,3]' AS distance
FROM items
ORDER BY distance
LIMIT 3;

The `probes` Query Parameter

At query time, you can further tune the search with the ivfflat.probes parameter. This setting controls how many of the nearest 'lists' (clusters) are actually searched.

  • More probes: Better recall, but slower search.
  • Fewer probes: Faster search, but potentially lower recall.

The default probes value is 1. You can set it for your session:

SET ivfflat.probes = 2;

SELECT id, embedding <-> '[1,2,3]' AS distance
FROM items
ORDER BY distance
LIMIT 3;

IVFFlat Indexing Check

Let's test your understanding of IVFFlat indexing.

IVFFlat: Key Takeaways

Great job! You've learned the fundamentals of IVFFlat indexing in pgvector.

  • IVFFlat speeds up ANN searches by partitioning data.
  • The lists parameter (index creation) controls the number of clusters.
  • The ivfflat.probes parameter (query time) controls how many clusters are searched.
  • Both involve a trade-off between search speed and recall.

Next, we'll explore HNSW indexing, another powerful option for even higher recall.

무료로 시작

AI 튜터와 함께 Vector Databases: Pinecone, Weaviate & pgvector을(를) 배우세요 — 무료

브라우저에서 실제 코드를 작성하고 실행하며, 24/7 AI 튜터로부터 즉각적인 도움을 받고, 웹이나 앱에서 중단한 부분부터 계속 학습하세요.

코스
12
레슨
48

자주 묻는 질문

“속도를 위한 IVFFlat 색인” 강의는 무료인가요?

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

“속도를 위한 IVFFlat 색인”에서 뭘 배우나요?

더 빠른 질의를 위해 pgvector에 IVFFlat 색인을 구현하여 근사 최근접 이웃 검색을 가속합니다. 브라우저에서 직접 실행하는 실습 코드로 Vector Databases: Pinecone, Weaviate & pgvector을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

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

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

“속도를 위한 IVFFlat 색인” 강의는 얼마나 걸리나요?

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

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

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

이 강의의 모든 강의

  1. 속도를 위한 IVFFlat 색인
  2. 재현율을 위한 HNSW 색인
  3. 질의 성능 조정
  4. 필터링된 검색 최적화
← Vector Databases: Pinecone, Weaviate & pgvector(으)로 돌아가기