PineconeDocumentStore

PineconeDocumentStore

Haystack에서 Pinecone 벡터 데이터베이스를 문서 저장소로 쓰려면 PineconeDocumentStore를 이용해요.

Pinecone은 클라우드 기반 벡터 데이터베이스예요. 빠르고 사용하기 쉬운 게 특징이에요. Qdrant나 Weaviate 같은 다른 솔루션과 달리 사용자 머신에서 로컬로 실행할 수는 없지만, 넉넉한 무료 티어(free tier)를 제공해요.

설치 (Installation)

Pinecone Haystack 통합은 아래처럼 간단히 설치할 수 있어요.

pip install pinecone-haystack

초기화 (Initialization)

  • Haystack에서 Pinecone을 Document Store로 쓰려면, 무료 Pinecone 계정에 가입하고 API 키를 받아요. Pinecone API 키는 명시적으로 넣거나, 환경 변수 PINECONE_API_KEY에서 자동으로 읽어올 수 있어요(후자를 권장).
  • Haystack에서 각 PineconeDocumentStore는 인덱스의 특정 네임스페이스에서 동작해요. 값을 주지 않으면 index와 namespace 둘 다 default예요. 인덱스가 이미 존재하면 Document Store는 그 인덱스에 연결하고, 없으면 새 인덱스를 만들어요.
  • 새 인덱스를 만들 때는 spec을 딕셔너리 형태로 제공할 수 있어요. 이걸로 serverless와 pod 배포 옵션을 고르고 추가 파라미터를 설정할 수 있어요. 자세한 내용은 Pinecone 문서를 참고하세요. 값을 주지 않으면 us-east-1 리전에 serverless로 배포하는 기본 spec이 사용돼요(무료 티어와 호환).
  • dimensionmetric도 제공할 수 있는데, Pinecone 인덱스가 이미 존재하지 않는 경우에만 반영돼요.

그리고 나서 Document Store를 아래처럼 사용해요.

from haystack import Document
from haystack_integrations.document_stores.pinecone import PineconeDocumentStore

# Make sure you have the PINECONE_API_KEY environment variable set
document_store = PineconeDocumentStore(
    index="default",
    namespace="default",
    dimension=5,
    metric="cosine",
    spec={"serverless": {"region": "us-east-1", "cloud": "aws"}},
)

document_store.write_documents(
    [
        Document(content="This is first", embedding=[0.1] * 5),
        Document(content="This is second", embedding=[0.1, 0.2, 0.3, 0.4, 0.5]),
    ],
)
print(document_store.count_documents())

지원하는 Retriever

출처: 공식문서