Skip to main content

Chroma / FAISS / LanceDB 를 같은 인터페이스로 비교하는 수업용 벡터 DB 데모

Project description

벡터 DB 실습: Chroma / FAISS / LanceDB

세 가지 벡터 데이터베이스에서 insert / update / delete / search (CRUD + 검색)를 같은 인터페이스로 구현하고 테스트해보는 수업용 예제.

구성

파일 내용
sample_data.py 공통 샘플 문서와 검색 질의
embedding.py 공통 임베딩 함수 (다국어 모델)
chroma_store.py Chroma — 텍스트만 넣으면 자동 임베딩
faiss_store.py FAISS — 벡터를 직접 만들어 인덱스에 추가
lancedb_store.py LanceDB — 벡터+원문을 한 테이블에 저장
test_stores.py 세 store 의 CRUD+검색을 한 번에 검증하는 pytest
test_chroma_features.py Chroma 특징: 자동 임베딩, 메타데이터/본문 필터
test_faiss_features.py FAISS 특징: L2/IP 척도, 인덱스 저장·로드, 배치 검색
test_lancedb_features.py LanceDB 특징: 필터+벡터검색 결합, 디스크 영속성

test_*_features.py 파일은 각 DB의 고유 기능을 보여준다. pytest로 검증할 수도, python test_chroma_features.py 처럼 직접 실행해 동작을 눈으로 볼 수도 있다.

비교 예제 (한 시나리오, 세 구현)

파일 내용
compare.py 세 DB를 같은 데이터·같은 시나리오로 돌려 특징을 나란히 비교
test_compare.py 구현은 달라도 결과가 동일한지 교차 검증

compare.py 는 세 DB를 동일한 인터페이스(insert/search/search_in_category)로 감싼 어댑터로 묶어, "카테고리 필터 + 검색"이라는 같은 시나리오를 처리한다. 같은 결과가 나오지만 필터 구현 방식이 다른 것이 핵심:

  • Chroma: where 메타데이터 필터 (네이티브)
  • LanceDB: SQL where prefilter (네이티브)
  • FAISS: 메타데이터가 없어 파이썬에서 직접 후필터링
python compare.py            # 특징 비교표 + A/B 시나리오 결과 출력
pytest test_compare.py -v

세 store 는 모두 동일한 메서드를 제공한다:

메서드 설명
insert(ids, texts) 문서 여러 개 추가
update(id, text) 문서 내용 교체 (임베딩도 재계산)
delete(id) 문서 삭제
get(id) ID로 원문 조회
count() 저장된 문서 수
search(query, k) 유사 상위 k개를 (id, 문서, 점수)로 반환

설치

uv pip install -r requirements.txt    # 또는 pip install -r requirements.txt

Python 3.12 이상 필요 (chromadb 의존성인 onnxruntime 이 3.11+ wheel만 제공).

실행 (각 DB의 CRUD 흐름 시연)

python chroma_store.py    # insert → search → update → delete 순서로 출력
python faiss_store.py
python lancedb_store.py

테스트

pytest test_stores.py -v

같은 CRUD 테스트(9개)를 세 백엔드에 모두 돌려 27개 케이스를 검증한다. 검색은 "유사도 검색을 해주는 저장소는?" 질의에 "벡터 데이터베이스는 임베딩을 저장하고 유사도로 검색한다." 문서를 1순위로 찾으면 정상이다.

핵심 차이 (수업 포인트)

임베딩 원문 저장 update/delete 저장 위치
Chroma 텍스트 넣으면 자동 O (자체 보관) id 지정 메모리/디스크
FAISS 직접 생성해 주입 X (dict로 직접 관리) IndexIDMap로 id 삭제, update는 삭제+재삽입 메모리
LanceDB 직접 생성해 주입 O (테이블 컬럼) SQL 같은 where 조건 디스크
  • Chroma: 가장 간단. 기본 임베딩은 영어용이라 여기선 다국어 모델을 지정했다.
  • FAISS: 순수 벡터 인덱스라 원문/ID 매핑을 직접 관리. 대규모·고속 검색에 강함.
  • LanceDB: 벡터와 메타데이터를 한 테이블에 저장, where 필터링 가능.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

vecdb_demo-0.1.0.tar.gz (193.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

vecdb_demo-0.1.0-py3-none-any.whl (13.2 kB view details)

Uploaded Python 3

File details

Details for the file vecdb_demo-0.1.0.tar.gz.

File metadata

  • Download URL: vecdb_demo-0.1.0.tar.gz
  • Upload date:
  • Size: 193.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for vecdb_demo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c6c5bd71a69d75a862d26c5d87a649e8c64d2e4919831541cce2c851167ea47f
MD5 d5f88ccff8b2ed389ca5b2cb4d06174c
BLAKE2b-256 f89b160a3bb1c7b1327e1f91aeb82d99e6f131f3f957a52dcc53e81607e429a5

See more details on using hashes here.

File details

Details for the file vecdb_demo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: vecdb_demo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for vecdb_demo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3bf6cdb19469818e4bdccd81b7d236ed109e3dc576260d744b0d6d2b1015cd0
MD5 f8b0c2ad0cf0ccd32924e61a8c74a67d
BLAKE2b-256 e7b5bc045855c18e3041a97560844a457728e0757218fd3a20beba317bfd922e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page