C.W.K.
Stream
Lesson 01 of 05 · published

PersistentClient 와 Collection

~18 min · chroma, setup

Level 0Scout
0 XP0/41 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

한 client, 여러 collection

Chroma client 는 디스크의 디렉토리를 가리켜. client 안에 collection 만들면 — 같은 on-disk store 를 공유하는 독립적 인덱스들이야. 일반적인 앱은 콘텐츠 타입당 collection 하나 (docs, conversations, code) 를 만들어서 각각 자기 임베딩 모델과 메타데이터 스키마 가지게 해.

distance metric 을 생성 시점에 박아

Chroma 는 cosine 이 default 인데 L2 나 inner product 도 골라. 생성 시점에 골라 — 기존 collection 의 metric 변경은 재빌드 필요해. 대부분 텍스트 use case 는 cosine 그대로 둬.

Code

Persistent client + collection 만들기·python
import chromadb
from chromadb.config import Settings

client = chromadb.PersistentClient(
    path='./chroma_store',
    settings=Settings(anonymized_telemetry=False),
)

docs = client.get_or_create_collection(
    name='handbook',
    metadata={'hnsw:space': 'cosine'},
)

print(client.list_collections())
print(docs.count())
connection 셋업 캡슐화·python
from functools import lru_cache

@lru_cache(maxsize=1)
def get_client():
    return chromadb.PersistentClient(path='./chroma_store',
                                     settings=Settings(anonymized_telemetry=False))

def get_collection(name: str):
    return get_client().get_or_create_collection(
        name=name, metadata={'hnsw:space': 'cosine'},
    )

External links

Exercise

두 디렉토리에 두 persistent client. 각각 collection 하나 만들어. 문서 몇 개 add. 디렉토리가 독립적이고, 한 client 디렉토리 삭제해도 다른 거 영향 없는 거 확인.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.