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

where 절로 메타데이터 거르기

~20 min · chroma, filtering

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

Chroma가 지원하는 필터 연산자

Chroma의 where 인자는 간단한 JSON 질의 언어야. 중요한 연산자는 다음과 같아.

  • $eq, $ne — 같음과 다름
  • $gt, $gte, $lt, $lte — 숫자나 문자열의 대소 비교
  • $in, $nin — 집합에 포함되는지 확인
  • $and, $or — 여러 조건을 논리적으로 결합

문서 본문에서 부분 문자열 찾기

청크 텍스트 자체에 특정 문자열이 들어 있는지 찾으려면 where_document를 써. 벡터 검색이 분명한 키워드를 놓칠 때 유용한 보조 수단이야. where_document={'$contains': 'OAuth'}를 더하면 Chroma 안에서 기본적인 키워드 필터를 적용할 수 있어.

Code

벡터 검색 + 메타데이터 필터 결합·python
res = docs.query(
    query_embeddings=q_vec,
    n_results=5,
    where={
        '$and': [
            {'project':  {'$eq':  'cwkPippa'}},
            {'doc_type': {'$in':  ['markdown', 'code']}},
            {'updated_at': {'$gte': '2026-04-01'}},
        ],
    },
    where_document={'$contains': 'embedding'},
    include=['documents', 'metadatas', 'distances'],
)

External links

Exercise

한 프로젝트의 최근 7일 청크 가운데 'OAuth'가 들어간 것만 고른 뒤, 쿼리와의 의미 유사도로 순위를 매기는 검색을 작성해. 필터가 후보 수를 절반으로 줄이면서도 순위 품질을 유지하는지 확인해.

Progress

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

댓글 0

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

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