FalkorDBDocumentStore
FalkorDBDocumentStore
GraphRAG 워크로드를 위해 Haystack에서 FalkorDB 그래프 데이터베이스를 사용하게 해 주는 Document Store예요.
출처: 문서
본문
FalkorDB는 GraphRAG 워크로드에 최적화된 고성능 그래프 데이터베이스예요. FalkorDBDocumentStore는 문서를 그래프 노드로 저장하고 네이티브 벡터 검색을 지원해요. APOC가 필요 없죠. 문서와 그 meta 필드는 각 노드에 평평하게 저장되고, 모든 일괄 쓰기는 UNWIND + MERGE를 사용해 안전한 OpenCypher upsert를 수행해요.
자세한 내용은 FalkorDB 문서를 참고하세요.
설치 (Installation)
FalkorDB를 Docker로 실행하세요.
docker run -d -p 6379:6379 falkordb/falkordb:latest
Haystack 통합을 설치하세요.
pip install falkordb-haystack
사용법 (Usage)
문서 스토어를 초기화하고 문서를 작성해요.
from haystack import Document
from haystack_integrations.document_stores.falkordb import FalkorDBDocumentStore
document_store = FalkorDBDocumentStore(
host="localhost",
port=6379,
embedding_dim=768,
recreate_graph=True,
)
document_store.write_documents(
[
Document(
content="There are over 7,000 languages spoken around the world today.",
),
Document(
content="Elephants have been observed to recognize themselves in mirrors.",
),
],
)
print(document_store.count_documents())
초기화 파라미터에 대해 더 자세히 알고 싶다면 API 문서를 참고하세요.
문서의 실제 임베딩을 계산하려면 SentenceTransformersDocumentEmbedder 같은 Document Embedder를 사용하세요.
인증 (Authentication)
비밀번호로 보호된 FalkorDB 인스턴스에 연결하려면 Secret으로 비밀번호를 전달하세요.
from haystack.utils import Secret
from haystack_integrations.document_stores.falkordb import FalkorDBDocumentStore
document_store = FalkorDBDocumentStore(
host="localhost",
port=6379,
password=Secret.from_env_var("FALKORDB_PASSWORD"),
)
유사도 함수 (Similarity Functions)
FalkorDBDocumentStore는 벡터 검색에 두 가지 유사도 함수를 지원해요.
"cosine"(기본값): 코사인 유사도. 정규화된 임베딩에 가장 좋아요."euclidean": 유클리드 거리. 임베딩의 크기가 중요할 때 유용해요.
document_store = FalkorDBDocumentStore(
host="localhost",
port=6379,
embedding_dim=768,
similarity="euclidean",
)
지원되는 리트리버 (Supported Retrievers)
FalkorDBEmbeddingRetriever: FalkorDB의 네이티브 벡터 인덱스를 사용해 벡터 유사도로FalkorDBDocumentStore에서 문서를 검색해요.FalkorDBCypherRetriever: 임의의 OpenCypher 쿼리를 실행해 문서를 검색해요. GraphRAG 파이프라인에서 그래프 탐색과 다중 홉 쿼리를 가능하게 해줘요.