AstraDocumentStore

AstraDocumentStore

API reference: Astra GitHub link: https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/astra

출처: 문서

본문

DataStax Astra DB는 Apache Cassandra 기반의 서버리스 벡터 데이터베이스로, 벡터 기반 검색과 자동 확장을 지원해요. AWS, GCP, Azure 어디에나 배포할 수 있고, 해당 클라우드 내 한 개 이상의 리전으로 쉽게 확장해 멀티 리전 가용성, 저지연 데이터 접근, 데이터 주권을 누리고 클라우드 벤더 종속도 피할 수 있어요. 자세한 내용은 DataStax 문서를 참고하세요.

Initialization

AstraDB 계정을 만들고 데이터베이스를 생성했다면 astra-haystack 통합을 설치하세요:

pip install astra-haystack

AstraDB 웹 UI의 설정에서 데이터베이스 API 엔드포인트와 생성된 토큰이 필요해요.

추가로 컬렉션 이름과 네임스페이스를 설정할 수 있어요. 컬렉션 이름은 기본값이 documents이고, 그와 함께 embedding_dimension과 similarity로 임베딩 차원과 유사도 지표를 설정할 수 있습니다. 네임스페이스는 데이터베이스 안의 데이터를 조직화하며 Apache Cassandra에서는 키스페이스(keyspace)라고 불러요.

그런 다음 Haystack에서 AstraDB 인스턴스에 연결된 AstraDocumentStore 객체를 초기화하고 문서를 작성하세요.

인증 데이터는 환경 변수로 전달하는 걸 강력히 권장합니다. 아래 예시를 실행하기 전에 ASTRA_DB_API_ENDPOINT와 ASTRA_DB_APPLICATION_TOKEN 환경 변수를 채워두세요.

from haystack import Document
from haystack_integrations.document_stores.astra import AstraDocumentStore

document_store = AstraDocumentStore()
document_store.write_documents(
    [Document(content="This is first"), Document(content="This is second")],
)
print(document_store.count_documents())

Supported Retrievers

AstraEmbeddingRetriever: Retriever에 제공된 쿼리 임베딩을 바탕으로 Document Store에서 문서를 가져오는 임베딩 기반 Retriever

Indexing Warnings

Astra DB Document Store를 만들 때 다음 경고 중 하나가 보일 수 있어요:

Astra DB collection ... is detected as having indexing turned on for all fields (either created manually or by older versions of this plugin). This implies stricter limitations on the amount of text each string in a document can store. Consider indexing anew on a fresh collection to be able to store longer texts.

또는:

Astra DB collection ... is detected as having the following indexing policy: {...}. This does not match the requested indexing policy for this object: {...}. In particular, there may be stricter limitations on the amount of text each string in a document can store. Consider indexing anew on a fresh collection to be able to store longer texts.

Why You See This Warning

컬렉션이 이미 존재하고 검색을 위한 모든 필드 인덱싱으로 설정되어 있기 때문이에요. 아마 이전에 직접 만들었거나 이전 플러그인 버전이 만들었을 거예요. Haystack이 컬렉션을 만들 때는 의도된 사용에 최적화된 인덱싱 정책을 적용합니다. 이 정책은 더 긴 텍스트를 저장하게 해주고, 필터링하지 않을 필드는 인덱싱하지 않아 쓰기 오버헤드도 줄여줘요.

Common Causes

  1. Haystack 밖에서 컬렉션을 만들었어요(예: Astra UI나 AstraPy의 Database.create_collection()).
  2. 이전 플러그인 버전으로 컬렉션을 만들었어요.

Impact

이것은 경고일 뿐이에요. 매우 긴 텍스트 필드를 저장하려고 하지 않는 한 애플리케이션은 계속 실행됩니다. 저장하려고 하면 Astra DB가 인덱싱 오류를 반환해요.

Solutions

  • 권장: 다시 채울 수 있다면 컬렉션을 드롭하고 재생성하세요. 그런 다음 Haystack 애플리케이션을 다시 실행해 최적화된 인덱싱 정책으로 컬렉션을 만들게 하세요.
  • 매우 긴 텍스트 필드를 저장하지 않을 게 확실하면 경고를 무시하세요.

더 알아보기 (Learn more)

🧑‍🍳 쿡북: Using AstraDB as a data store in your Haystack pipelines