Skip to main content

Install the SDK

pip install nined-memory

Set Up Your Client

Sign up at 9dlabs.xyz/signup to get an API key. Your base URL is https://api.9dlabs.xyz.
from nined.memory import MemoryClient

client = MemoryClient(base_url="https://api.9dlabs.xyz", api_key="your-key")

Store Your First Artifact

Ingest a document into a workspace:
client.ingest(
    workspace_id="my-app",
    actor_id="system",
    artifact_type="document",
    raw_payload={
        "title": "Refund Policy",
        "content": "Refunds are accepted within 30 days of purchase. No refunds after 30 days."
    },
    idempotency_key="doc_refund_policy_v1",
)

Retrieve a Context Pack

Query for relevant context within a token budget:
pack = client.context_pack(
    query="Can I get a refund for a 45-day-old purchase?",
    workspace_id="my-app",
    max_tokens=1024,
)

if pack["abstain_flag"]:
    print("Insufficient memory to answer.")
else:
    print(pack["context_text"])       # Ready to inject into your LLM
    print(f"Confidence: {pack['confidence']:.0%}")
    print(f"Receipt: {pack['receipt_id']}")

Use the Context in Your LLM

The context_text field is a ready-to-inject prompt string with [cite:N] markers:
from openai import OpenAI

oai = OpenAI()

completion = oai.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {
            "role": "system",
            "content": (
                "Answer using ONLY the provided context. "
                "Cite sources using [cite:N] format.\n\n"
                + pack["context_text"]
            ),
        },
        {"role": "user", "content": "Can I get a refund for a 45-day-old purchase?"},
    ],
    temperature=0,
)

print(completion.choices[0].message.content)

Next Steps

API Reference

Full reference for every endpoint.

Agent Integration

The complete ingest-query-feedback loop for production agents.

Python SDK

All methods for the nined-memory Python SDK.

Core Concepts

Understand decision receipts, confidence, and policies.