RAGStack AI Knowledge Store

0.2.1 · active · verified Fri Apr 17

ragstack-ai-knowledge-store is a component of the DataStax RAGStack AI ecosystem, focusing on graph-based knowledge storage and retrieval. It allows users to build and query knowledge graphs backed by Astra DB, DataStax's cloud-native database. The current version is 0.2.1. While the main `ragstack-ai` project has frequent releases, this sub-package's versioning may not always align directly with the primary project's major versions.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize `AstraDBKnowledgeStore` and add `langchain_core.documents.Document` objects to it. It requires an active Astra DB instance and valid credentials. The `graph_name` parameter identifies your specific knowledge graph within Astra DB.

import os
from ragstack_ai.knowledge_store import AstraDBKnowledgeStore
from langchain_core.documents import Document

# Ensure Astra DB credentials are set as environment variables
# ASTRA_DB_APPLICATION_TOKEN, ASTRA_DB_ID, ASTRA_DB_KEYSPACE (optional, defaults to 'default')

astra_db_token = os.environ.get("ASTRA_DB_APPLICATION_TOKEN", "YOUR_ASTRA_DB_TOKEN")
astra_db_id = os.environ.get("ASTRA_DB_ID", "YOUR_ASTRA_DB_ID")
astra_db_keyspace = os.environ.get("ASTRA_DB_KEYSPACE", "default")

if not all([astra_db_token, astra_db_id]):
    print("Please set ASTRA_DB_APPLICATION_TOKEN and ASTRA_DB_ID environment variables.")
    exit()

try:
    # Initialize the Knowledge Store
    kg_store = AstraDBKnowledgeStore(
        astra_db_id=astra_db_id,
        astra_db_application_token=astra_db_token,
        astra_db_keyspace=astra_db_keyspace,
        graph_name="my_rag_knowledge_graph" # A unique name for your graph
    )

    # Add documents to the knowledge store
    documents = [
        Document(page_content="Leonardo da Vinci was an Italian polymath.", metadata={"source": "wiki"}),
        Document(page_content="The Mona Lisa is a half-length portrait painting by Leonardo da Vinci.", metadata={"source": "wiki"})
    ]

    print("Adding documents...")
    kg_store.add_documents(documents=documents)
    print("Documents added successfully.")

    # Example: Simple graph traversal (conceptual, actual queries depend on graph structure)
    # Note: Complex graph queries typically use specific methods or a dedicated graph query engine.
    # This demonstrates basic interaction.
    print(f"Knowledge Store initialized for graph: {kg_store.graph_name}")

except Exception as e:
    print(f"An error occurred: {e}")
    print("Ensure your Astra DB credentials are correct and the database is accessible.")

view raw JSON →