Context Engineering

⏱️ Time to Complete: 15 minutes 🎯 Level: Intermediate 💻 Language: TypeScript

What You'll Learn

2025 patterns for semantic memory:

  • ✅ Form memory intentionally (summaries, entities, embeddings)

  • ✅ Retrieve the right slice of context every time

  • ✅ Align conversations to domains, tenants, and entities

  • ✅ Control context windows and reranking without hand-editing prompts

  • ✅ Ship production-safe retrieval with the same configuration the Graphlit SDK uses in Zine

📁 Reference implementation


Prerequisites

  • Complete the Quickstart tutorial

  • Graphlit credentials configured in .env (from Getting Started guide)

  • npm install graphlit-client dotenv

Need Python or .NET samples? Open Ask Graphlit inside the Developer Portal (or visit ask.graphlit.dev) and it will translate every call shown here into your SDK of choice.


Shared Setup


Pattern 1 – Form the Right Memory Up Front

Create a workflow that produces summaries, extracts entities, and respects your chunk budget before anything hits retrieval.

Run once:

Ingest with the Workflow

Resulting content now ships with:

  • Summaries referenced by content.summary

  • Extracted observations for people, orgs, products, events

  • Images preserved for downstream vision models


Pattern 2 – Retrieval That Matches the Question

Hybrid vs Keyword vs Vector

Use Hybrid by default, fall back to Keyword when you need exact IDs or error codes, and Vector for conceptual prompts.

Filter to the Right Domain and Entity

Filtering on collections, feeds, or observations keeps retrieval scoped to the exact tenant, product line, or account team that matters to the current user.


Pattern 3 – Specifications That Enforce Context Rules

Build a conversation specification once, reuse it everywhere.

  • Section retrieval keeps context slices coherent (page/segment level).

  • Reranking uses Cohere to score relevance before prompts see the content.

  • chunkTokenLimit ensures embeddings stay under the LLM’s budget.


Pattern 4 – Conversations that Stay in Bounds

The conversation never sees content outside the selected collection or organization. Tenants stay isolated without writing manual guardrails.


Pattern 5 – Keep the Window Fresh

Quickly Re-run with Updated Filters

Poll for Newly Processed Content Before Prompting

Ensuring ingestion is finished before prompting avoids stale context and reduces retries.


Production Checklist

  • Persist IDs: Store specification, workflow, collection, and entity IDs in configuration so every service call reuses the exact same context rules.

  • Log retrieval metadata: Inspect response.promptConversation.details?.sources to validate which documents powered answers.

  • Segment tenants early: Collections or feeds per tenant keep context surfaces clean and simplify billing/quotas.

  • Tune once: Adjust retrieval/reranking directly on the specification instead of ad-hoc prompt engineering.

  • Fallbacks: Provide multiple specifications via fallbacks if different models handle niche cases better (e.g., legal vs. product queries).


Next Steps


Build context that respects your product and your customers. Build with Graphlit.

Last updated

Was this helpful?