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.2.0.tar.gz (7.2 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.2.0-py3-none-any.whl (10.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: substrate_haystack-0.2.0.tar.gz
  • Upload date:
  • Size: 7.2 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.2.0.tar.gz
Algorithm Hash digest
SHA256 07a0bbc0559bbd50f5eec67349bea907a3889eb2df172add20ae79cea6e00064
MD5 f2fdca401a28799ce51bd98ab8d9f395
BLAKE2b-256 89b94429adae243ce887243a4ab79dda554a4ed545cb1bdb8e3f259266ed44c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for substrate_haystack-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b9e2ded06a0668a3d0df9e57ce64beb5de2dcf3204b571ce05672ca21e853200
MD5 c17de3ab035754ea0b769253f798f4f3
BLAKE2b-256 2a1256b84dbb7dd488dace58ec072ae863db58dc0617034e7d1e5dc625fb2153

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