Supabase (Postgres)의 벡터스토어 사용하기

in #blog21 days ago (edited)

Supabse는 500MB DB를 무료로 사용가능합니다. 이 정도 용량이면 책 몇권정도의 임베딩을 저장하기 하기에는 충분합니다.

제가 사용하려는 bge-m3 임베딩 모델의 Dimension은 1024이므로 embedding vector를 1024로 생성합니다.

-- Enable the pgvector extension to work with embedding vectors
create extension if not exists vector;

-- Create a table to store your documents
create table
  documents (
    id uuid primary key,
    content text, -- corresponds to Document.pageContent
    metadata jsonb, -- corresponds to Document.metadata
    embedding vector (1024) -- 1024 works for bge-m3 embeddings, change if needed
  );

-- Create a function to search for documents
create function match_documents (
  query_embedding vector (1024),
  filter jsonb default '{}'
) returns table (
  id uuid,
  content text,
  metadata jsonb,
  similarity float
) language plpgsql as $$
#variable_conflict use_column
begin
  return query
  select
    id,
    content,
    metadata,
    1 - (documents.embedding <=> query_embedding) as similarity
  from documents
  where metadata @> filter
  order by documents.embedding <=> query_embedding;
end;
$$;


Supabase DB에는 아래와 같은 형태의 데이터가 입력됩니다.


응답 속도가 느릴 줄 알았는데 쿼리하면 0.5초 내에 결과를 리턴합니다.

참고: https://python.langchain.com/docs/integrations/vectorstores/supabase/

Posted using Obsidian Steemit plugin

Sort:  

[광고] STEEM 개발자 커뮤니티에 참여 하시면, 다양한 혜택을 받을 수 있습니다.

Congratulations, your post has been upvoted by @upex with a 0.20% upvote. We invite you to continue producing quality content and join our Discord community here. Keep up the good work! #upex

오 이것은 뭐하는 디비 인가요?

그냥 Postgresql 입니다. Postgresql이 벡터 검색을 지원한다고 해서 사용해봤습니다.
그리고 pgvecot은 오픈소스에요: https://github.com/pgvector/pgvector

감사합니다. ^^ 한번 써봐야겠네요 벡터 검색 ^^

Coin Marketplace

STEEM 0.30
TRX 0.11
JST 0.031
BTC 67803.71
ETH 3800.05
USDT 1.00
SBD 3.66