ChromaQueryTextRetriever
ChromaQueryTextRetriever
Chroma Document Store와 호환되는 Retriever예요.
출처: 문서
본문
| 항목 | 내용 |
|---|---|
| 파이프라인에서의 일반적인 위치 | 1. RAG 파이프라인에서 Text Embedder 이후, PromptBuilder 이전 / 2. 의미 검색(semantic search) 파이프라인의 마지막 컴포넌트 / 3. 추출형 QA 파이프라인에서 Text Embedder 이후, TransformersExtractiveReader 이전 |
| 필수 init 변수 | document_store — ChromaDocumentStore의 인스턴스 |
| 필수 run 변수 | query — Retriever가 처리할 평문 형식의 단일 쿼리 |
| 출력 변수 | documents — 문서 리스트 |
| API reference | Chroma |
| GitHub link | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/chroma |
| Package name | chroma-haystack |
Overview
ChromaQueryTextRetriever는 ChromaDocumentStore와 호환되는 임베딩 기반 Retriever로, Chroma 쿼리 API를 사용해요.
이 컴포넌트는 평문 쿼리 문자열을 입력받아 일치하는 문서를 반환합니다.
Chroma가 쿼리 임베딩을 자체 embedding function으로 만들어요. 기본 임베딩 함수를 쓰고 싶지 않다면 ChromaDocumentStore 초기화 시점에 지정해야 합니다.
Usage
On its own
이 Retriever를 실행하려면 ChromaDocumentStore와 인덱싱된 문서가 필요합니다.
from haystack_integrations.document_stores.chroma import ChromaDocumentStore
from haystack_integrations.components.retrievers.chroma import ChromaQueryTextRetriever
document_store = ChromaDocumentStore()
retriever = ChromaQueryTextRetriever(document_store=document_store)
# example run query
retriever.run(query="How does Chroma Retriever work?")
In a pipeline
파이프라인에서 ChromaQueryTextRetriever를 사용하는 방법이에요. 이 예시에서는 인덱싱 파이프라인과 쿼리 파이프라인 두 개를 만들게 됩니다.
인덱싱 파이프라인에서는 문서를 Document Store에 씁니다.
그리고 쿼리 파이프라인에서는 ChromaQueryTextRetriever가 주어진 쿼리를 바탕으로 Document Store에서 답을 얻어요.
import os
from pathlib import Path
from haystack import Pipeline
from haystack.dataclasses import Document
from haystack.components.writers import DocumentWriter
from haystack_integrations.document_stores.chroma import ChromaDocumentStore
from haystack_integrations.components.retrievers.chroma import ChromaQueryTextRetriever
# Chroma is used in-memory so we use the same instances in the two pipelines below
document_store = ChromaDocumentStore()
documents = [
Document(content="This contains variable declarations", meta={"title": "one"}),
Document(
content="This contains another sort of variable declarations",
meta={"title": "two"},
),
Document(
content="This has nothing to do with variable declarations",
meta={"title": "three"},
),
Document(content="A random doc", meta={"title": "four"}),
]
indexing = Pipeline()
indexing.add_component("writer", DocumentWriter(document_store))
indexing.run({"writer": {"documents": documents}})
querying = Pipeline()
querying.add_component("retriever", ChromaQueryTextRetriever(document_store))
results = querying.run({"retriever": {"query": "Variable declarations", "top_k": 3}})
for d in results["retriever"]["documents"]:
print(d.meta, d.score)
Additional References
- 🧑🍳 Cookbook: Use Chroma for RAG and Indexing
더 알아보기 (Learn more)
- ChromaQueryTextRetriever — Haystack 공식 문서