Last updated

LangChain Retriever Example

Use Papr as a retrieval backend inside a LangChain workflow.

Pattern

  1. Query Papr memory search with enable_agentic_graph=true.
  2. Convert memories/nodes to LangChain Document objects.
  3. Pass into your chain or agent executor.

Prerequisites

  • PAPR_MEMORY_API_KEY in your environment
  • LangChain runtime with langchain_core

Minimal Setup

  1. Run papr_retrieve() for a test query.
  2. Confirm at least one Document object is returned.

Python Skeleton

from papr_memory import Papr
from langchain_core.documents import Document
import os

client = Papr(x_api_key=os.environ.get("PAPR_MEMORY_API_KEY"))

def papr_retrieve(query: str, external_user_id: str):
    result = client.memory.search(
        query=query,
        external_user_id=external_user_id,
        enable_agentic_graph=True,
    )
    docs = []
    for item in result.data.get("memories", []):
        docs.append(Document(page_content=item["content"], metadata={"id": item.get("id")}))
    return docs

Validation Checklist

  • Retrieval call succeeds with enable_agentic_graph=true.
  • Returned docs include memory id metadata.

Troubleshooting

If docs are empty, verify user scope (external_user_id) and broaden query terms before tuning thresholds.