본문 바로가기
C.W.K.
Stream
Lesson 01 of 05 · published

PersistentClient와 컬렉션

~18 min · chroma, setup

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

클라이언트 하나에 여러 컬렉션

Chroma의 클라이언트는 디스크의 한 디렉터리를 가리켜. 그 안에 컬렉션을 만들면 같은 디스크 저장소를 공유하면서도 서로 독립적인 인덱스로 동작해. 일반적인 앱은 문서, 대화, 코드처럼 콘텐츠 형식마다 컬렉션을 하나씩 만들고 각각 알맞은 임베딩 모델과 메타데이터 스키마를 지정해.

거리 척도는 만들 때 정해

Chroma의 기본값은 코사인이지만 L2나 내적도 선택할 수 있어. 기존 컬렉션의 거리 척도를 바꾸려면 다시 구축해야 하므로 생성할 때 정해야 해. 대부분의 텍스트 검색에는 코사인을 그대로 쓰면 돼.

Code

영속 클라이언트와 컬렉션 만들기·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())
연결 설정을 함수로 감싸기·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

서로 다른 두 디렉터리에 영속 클라이언트를 하나씩 만들고, 각각 컬렉션 하나와 문서 몇 개를 추가해. 두 디렉터리가 독립적이며 한쪽 클라이언트 디렉터리를 지워도 다른 쪽에는 영향이 없는지 확인해.

Progress

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

댓글 0

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

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