Skip to main content

stache-ai-dynamodb

DynamoDB providers for Stache AI - serverless namespace registry and document index for AWS Lambda deployments.

Installation

pip install stache-ai-dynamodb

Providers

This package includes two providers:

Provider Type Description
dynamodb Namespace Hierarchical namespace registry with parent-child relationships
dynamodb Document Index Document metadata storage with namespace filtering

Configuration

from stache_ai.config import Settings

settings = Settings(
    namespace_provider="dynamodb",
    dynamodb_namespace_table="my-namespaces",  # Required

    # Optional: Document index
    enable_document_index=True,
    document_index_provider="dynamodb",
    dynamodb_document_table="my-documents",
)

Environment Variables

Variable Description Default
NAMESPACE_PROVIDER Set to dynamodb none
DYNAMODB_NAMESPACE_TABLE Namespace table name Required
DOCUMENT_INDEX_PROVIDER Set to dynamodb none
DYNAMODB_DOCUMENT_TABLE Document table name Required if using document index
AWS_REGION AWS region us-east-1

Table Schemas

Namespace Table

Primary key: id (String) GSI: parent_id-index on parent_id (String)

Attribute Type Description
id String Unique namespace identifier (primary key)
name String Display name
description String Optional description
parent_id String Parent namespace ID (__ROOT__ for top-level)
metadata String JSON-encoded metadata
filter_keys String JSON-encoded list of filter keys
created_at String ISO 8601 timestamp
updated_at String ISO 8601 timestamp

Document Table

Uses single-table design with composite keys:

Primary Key:

  • PK (String): DOC#{namespace}#{doc_id}
  • SK (String): METADATA

Global Secondary Indexes:

  • GSI1: Namespace queries
    • GSI1PK: NAMESPACE#{namespace}
    • GSI1SK: CREATED#{timestamp}
  • GSI2: Filename lookups
    • GSI2PK: FILENAME#{namespace}#{filename}
    • GSI2SK: CREATED#{timestamp}
Attribute Type Description
PK String Primary key: DOC#{namespace}#{doc_id}
SK String Sort key: METADATA
GSI1PK String Namespace index: NAMESPACE#{namespace}
GSI1SK String Created timestamp: CREATED#{timestamp}
GSI2PK String Filename index: FILENAME#{namespace}#{filename}
GSI2SK String Created timestamp: CREATED#{timestamp}
doc_id String Document ID
namespace String Namespace ID
filename String Original filename
title String Document title
source String Source identifier
content_type String MIME type
chunk_count Number Number of chunks
metadata Map Document metadata
created_at String ISO 8601 timestamp
updated_at String ISO 8601 timestamp

Infrastructure Examples

AWS SAM Template

Resources:
  # Namespace registry table
  NamespaceTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: !Sub '${AWS::StackName}-namespaces'
      BillingMode: PAY_PER_REQUEST
      AttributeDefinitions:
        - AttributeName: id
          AttributeType: S
        - AttributeName: parent_id
          AttributeType: S
      KeySchema:
        - AttributeName: id
          KeyType: HASH
      GlobalSecondaryIndexes:
        - IndexName: parent_id-index
          KeySchema:
            - AttributeName: parent_id
              KeyType: HASH
          Projection:
            ProjectionType: ALL

  # Document index table (single-table design)
  DocumentsTable:
    Type: AWS::DynamoDB::Table
    Properties:
      TableName: !Sub '${AWS::StackName}-documents'
      BillingMode: PAY_PER_REQUEST
      AttributeDefinitions:
        - AttributeName: PK
          AttributeType: S
        - AttributeName: SK
          AttributeType: S
        - AttributeName: GSI1PK
          AttributeType: S
        - AttributeName: GSI1SK
          AttributeType: S
        - AttributeName: GSI2PK
          AttributeType: S
        - AttributeName: GSI2SK
          AttributeType: S
      KeySchema:
        - AttributeName: PK
          KeyType: HASH
        - AttributeName: SK
          KeyType: RANGE
      GlobalSecondaryIndexes:
        - IndexName: GSI1
          KeySchema:
            - AttributeName: GSI1PK
              KeyType: HASH
            - AttributeName: GSI1SK
              KeyType: RANGE
          Projection:
            ProjectionType: ALL
        - IndexName: GSI2
          KeySchema:
            - AttributeName: GSI2PK
              KeyType: HASH
            - AttributeName: GSI2SK
              KeyType: RANGE
          Projection:
            ProjectionType: ALL

  # Lambda function with DynamoDB access
  StacheFunction:
    Type: AWS::Serverless::Function
    Properties:
      Environment:
        Variables:
          NAMESPACE_PROVIDER: dynamodb
          DYNAMODB_NAMESPACE_TABLE: !Ref NamespaceTable
          DOCUMENT_INDEX_PROVIDER: dynamodb
          DYNAMODB_DOCUMENT_TABLE: !Ref DocumentsTable
      Policies:
        - DynamoDBCrudPolicy:
            TableName: !Ref NamespaceTable
        - DynamoDBCrudPolicy:
            TableName: !Ref DocumentsTable

Terraform

resource "aws_dynamodb_table" "namespaces" {
  name         = "${var.prefix}-namespaces"
  billing_mode = "PAY_PER_REQUEST"
  hash_key     = "id"

  attribute {
    name = "id"
    type = "S"
  }

  attribute {
    name = "parent_id"
    type = "S"
  }

  global_secondary_index {
    name            = "parent_id-index"
    hash_key        = "parent_id"
    projection_type = "ALL"
  }
}

resource "aws_dynamodb_table" "documents" {
  name         = "${var.prefix}-documents"
  billing_mode = "PAY_PER_REQUEST"
  hash_key     = "PK"
  range_key    = "SK"

  attribute {
    name = "PK"
    type = "S"
  }

  attribute {
    name = "SK"
    type = "S"
  }

  attribute {
    name = "GSI1PK"
    type = "S"
  }

  attribute {
    name = "GSI1SK"
    type = "S"
  }

  attribute {
    name = "GSI2PK"
    type = "S"
  }

  attribute {
    name = "GSI2SK"
    type = "S"
  }

  global_secondary_index {
    name            = "GSI1"
    hash_key        = "GSI1PK"
    range_key       = "GSI1SK"
    projection_type = "ALL"
  }

  global_secondary_index {
    name            = "GSI2"
    hash_key        = "GSI2PK"
    range_key       = "GSI2SK"
    projection_type = "ALL"
  }
}

AWS CLI

# Create namespace table
aws dynamodb create-table \
  --table-name stache-namespaces \
  --attribute-definitions \
    AttributeName=id,AttributeType=S \
    AttributeName=parent_id,AttributeType=S \
  --key-schema AttributeName=id,KeyType=HASH \
  --global-secondary-indexes \
    'IndexName=parent_id-index,KeySchema=[{AttributeName=parent_id,KeyType=HASH}],Projection={ProjectionType=ALL}' \
  --billing-mode PAY_PER_REQUEST

# Create documents table
aws dynamodb create-table \
  --table-name stache-documents \
  --attribute-definitions \
    AttributeName=PK,AttributeType=S \
    AttributeName=SK,AttributeType=S \
    AttributeName=GSI1PK,AttributeType=S \
    AttributeName=GSI1SK,AttributeType=S \
    AttributeName=GSI2PK,AttributeType=S \
    AttributeName=GSI2SK,AttributeType=S \
  --key-schema \
    AttributeName=PK,KeyType=HASH \
    AttributeName=SK,KeyType=RANGE \
  --global-secondary-indexes \
    'IndexName=GSI1,KeySchema=[{AttributeName=GSI1PK,KeyType=HASH},{AttributeName=GSI1SK,KeyType=RANGE}],Projection={ProjectionType=ALL}' \
    'IndexName=GSI2,KeySchema=[{AttributeName=GSI2PK,KeyType=HASH},{AttributeName=GSI2SK,KeyType=RANGE}],Projection={ProjectionType=ALL}' \
  --billing-mode PAY_PER_REQUEST

IAM Permissions

The Lambda function needs these permissions on both tables:

- dynamodb:DescribeTable
- dynamodb:GetItem
- dynamodb:PutItem
- dynamodb:UpdateItem
- dynamodb:DeleteItem
- dynamodb:Query
- dynamodb:Scan

Or use the SAM DynamoDBCrudPolicy as shown above.

Requirements

  • Python >= 3.10
  • stache-ai >= 0.1.0
  • boto3 >= 1.34.0

Metadata

Release files for stache-ai-dynamodb 0.2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stache-ai-dynamodb 0.2.0
File Size Uploaded Provenance Actions
stache_ai_dynamodb-0.2.0.tar.gz 40.1 kB Without provenance Details for stache_ai_dynamodb-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for stache-ai-dynamodb 0.2.0
File Interpreter ABI Platform Actions
stache_ai_dynamodb-0.2.0-py3-none-any.whl Python 3 none any Details for stache_ai_dynamodb-0.2.0-py3-none-any.whl

Total release size: 63.3 kB

Release files / stache_ai_dynamodb-0.2.0.tar.gz

Download URL stache_ai_dynamodb-0.2.0.tar.gz
Size 40.1 kB
Tags Source
SHA-256 checksum
How to use checksums
de9267296e18ee10efff03c92fc1ad009e4eae0ced20f83a5f4a6a61eda6b028
BLAKE2b-256 checksum
How to use checksums
35facfe524f9246a51b67757732a99aefbd8af601ba34cbfe20b083e87369e8d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Release files / stache_ai_dynamodb-0.2.0-py3-none-any.whl

Download URL stache_ai_dynamodb-0.2.0-py3-none-any.whl
Size 23.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c1531622c0d688f0c0a5d9f84c48c461f4dd17ed72eec8af5c19d3f8dfcd29dc
BLAKE2b-256 checksum
How to use checksums
10b74961e14602d4b0ac0d6a3c965b678361ea925b5c9325c84c67609dfcce0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.3

Security for stache-ai-dynamodb 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page