Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Step-by-step guide to giving an AI assistant persistent long-term memory across sessions.
from piyapi_memory import PiyAPIClient client = PiyAPIClient(api_key="sk_live_your_api_key_here") def chat_turn(user_id: str, prompt: str) -> str: # Step 1: Recall relevant facts using hybrid RRF scoring context_records = client.search.query( query=prompt, filter={"metadata.user_id": user_id}, limit=4 ) # Step 2: Format context injection memory_context = "\n".join([f"- {r['content']}" for r in context_records['results']]) # Step 3: Run LLM inference with augmented context system_prompt = f"""You are a helpful personal companion. User Background & Memories: {memory_context}""" # Step 4: After replying, mine new facts for persistence client.memories.create( content=prompt, tags=["conversation"], metadata={"user_id": user_id} ) return "Response generated with active context."