LangChain Retriever Example
Use Papr as a retrieval backend inside a LangChain workflow.
Pattern
- Query Papr memory search with
enable_agentic_graph=true. - Convert memories/nodes to LangChain
Documentobjects. - Pass into your chain or agent executor.
Prerequisites
PAPR_MEMORY_API_KEYin your environment- LangChain runtime with
langchain_core
Minimal Setup
- Run
papr_retrieve()for a test query. - Confirm at least one
Documentobject 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 docsValidation Checklist
- Retrieval call succeeds with
enable_agentic_graph=true. - Returned docs include memory
idmetadata.
Troubleshooting
If docs are empty, verify user scope (external_user_id) and broaden query terms before tuning thresholds.