Skip to main content

SUBSTRATE memory components for Haystack -- causal memory, emotion, and identity retrieval and storage.

Project description

substrate-haystack

SUBSTRATE memory components for Haystack pipelines. Retriever and writer that connect Haystack to SUBSTRATE's causal memory, emotional state, and identity continuity.

What SUBSTRATE adds to Haystack

  • Causal memory retrieval -- episodes linked by cause-effect rules, not just vector similarity
  • Emotional context output -- retriever exposes the entity's emotional state alongside documents
  • Persistent storage -- writer stores documents through the entity's full cognitive pipeline
  • Hybrid search -- semantic + keyword retrieval across the entity's full knowledge store
  • Identity continuity -- cryptographically verified entity state persists across sessions

Installation

pip install substrate-haystack

Quick start: Retrieval pipeline

import os
from haystack import Pipeline
from haystack.components.generators import OpenAIGenerator
from haystack.components.builders import PromptBuilder
from substrate_haystack import SubstrateMemoryRetriever

retriever = SubstrateMemoryRetriever(
    api_key=os.environ["SUBSTRATE_API_KEY"],
)

prompt_builder = PromptBuilder(
    template="""
    Context from SUBSTRATE memory:
    {% for doc in documents %}
    - {{ doc.content }}
    {% endfor %}

    Entity emotional state: {{ entity_state }}

    Question: {{ query }}
    Answer:
    """
)

generator = OpenAIGenerator(model="gpt-4o")

pipe = Pipeline()
pipe.add_component("retriever", retriever)
pipe.add_component("prompt_builder", prompt_builder)
pipe.add_component("llm", generator)

pipe.connect("retriever.documents", "prompt_builder.documents")
pipe.connect("retriever.entity_state", "prompt_builder.entity_state")
pipe.connect("prompt_builder", "llm")

result = pipe.run({
    "retriever": {"query": "What patterns have we identified?"},
    "prompt_builder": {"query": "What patterns have we identified?"},
})

print(result["llm"]["replies"][0])

Quick start: Writing to memory

from haystack import Document, Pipeline
from substrate_haystack import SubstrateMemoryWriter

writer = SubstrateMemoryWriter(
    api_key=os.environ["SUBSTRATE_API_KEY"],
)

pipe = Pipeline()
pipe.add_component("writer", writer)

result = pipe.run({
    "writer": {
        "documents": [
            Document(content="The team decided to use event sourcing for the audit trail."),
            Document(content="Performance testing showed 99th percentile at 45ms."),
        ]
    }
})

print(f"Stored {result['writer']['documents_written']} documents")

Components

SubstrateMemoryRetriever

Retrieves documents from SUBSTRATE memory using hybrid search.

Inputs:

Name Type Description
query str Search query string
top_k int Maximum results to return (default 5)

Outputs:

Name Type Description
documents list[Document] Retrieved documents from SUBSTRATE memory
entity_state dict Entity emotional state (UASV dimensions)

Parameters:

Parameter Default Description
api_key $SUBSTRATE_API_KEY Your SUBSTRATE API key
base_url https://substrate.garmolabs.com/mcp-server/mcp MCP server endpoint
timeout 30.0 HTTP request timeout (seconds)
include_emotion True Fetch emotional context with results

SubstrateMemoryWriter

Stores documents into SUBSTRATE memory via the respond tool.

Inputs:

Name Type Description
documents list[Document] Documents to store in memory

Outputs:

Name Type Description
documents_written int Number of documents successfully stored
responses list[str] Entity responses for each document

API key

Get your API key at garmolabs.com. The free tier includes memory_search and get_emotion_state. Upgrade to Pro for hybrid_search and get_trust_state.

License

MIT -- see LICENSE for details.

Built by Garmo Labs.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

substrate_haystack-0.1.2.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

substrate_haystack-0.1.2-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file substrate_haystack-0.1.2.tar.gz.

File metadata

  • Download URL: substrate_haystack-0.1.2.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for substrate_haystack-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8e37f9be8f06d05feb0018d0278213ca3ae836574a19b604f9a88c3d2aba794f
MD5 5def5d89a0bc6b1425477f3cef23fd01
BLAKE2b-256 4bc87881f88f45621f83d6808d84e4a690fffff2a2bb82794d2c46d6a0b0bbe0

See more details on using hashes here.

File details

Details for the file substrate_haystack-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for substrate_haystack-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 64f7bfb72262eeaeaac9dbffc8757fdf9f32f08fd2ea3970a745846509825f11
MD5 bdafe6675477c66a488ec9dedc48e253
BLAKE2b-256 70decd95cc02a09ba5cbe715ab26c73377adcf06050b146c857593c8ab714ca4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page