Status: In Development · Playground demo coming soon.
The recipe below is complete and runnable today on an Instance with documents enabled; only the hosted playground showcase is pending.
What you’ll build
- Upload a set of policy and handbook files once, shared across your whole application
- Answer each question from the passages Synap returns, and nothing else
- Cite every answer with the document, section and page it came from
- Show the source: open the original file behind a citation
- Update a policy by uploading it again; the assistant serves the latest version
When to use this recipe
Build this if:- Your agent’s knowledge lives in files rather than in conversations
- Everyone using the agent should see the same knowledge (company-wide policies, product docs)
- People need to verify an answer, not just trust it
- The documents change over time and the agent must follow
Architecture at a glance
Stack
Prerequisites
- A Synap API key. See Authentication
- Documents enabled on your Instance. Without them, an upload is refused
- Python: Python 3.11+. TypeScript: Node.js 20+
Build it
1. Choose a scope
A document is filed at the scope you name when you upload it, the same way a memory is. Company-wide knowledge goes at client scope: send nouser_id and no customer_id, and every user of your application can find it. Knowledge for one customer takes a customer_id on a B2B Instance, and knowledge for one person takes a user_id. See Memory scopes.
This recipe uses client scope, so the uploads and the fetch below carry no ids.
2. Upload the files
Give each file a stabledocument_id. It is how Synap knows a later upload is the same document.
document_type="policy" (document_type: 'policy' in TypeScript, JavaScript 0.9.0 and later).
3. Wait until the files are searchable
Uploads return at once; reading and indexing happen in the background. A file can be found as soon as it issearchable.
4. Answer with citations
Fetch the passages for the question, hand only those to your model, and return the answer with the citations of the passages.ask_llm and askLlm stand for your own model call. Synap returns the citations; how you show them is yours to decide. See Citations for every field.
5. Show the source
When a user clicks a source, open the original file of the version that was cited.documents.original returns the file’s bytes: stream them to the browser or save them. It answers only for documents the caller may see, so a source without a document_key is shown as a citation only.
Run & verify
returns-policy.md, upload it again with the same document_id, wait until it is searchable, and ask again: the answer follows the new text and the citation’s version goes up by one.
Customize / extend
- One knowledge base per customer → upload with
customer_idand fetch withsdk.customer.context.fetch(customer_id=...)on a B2B Instance. - Only quotes from documents → pass
kinds=["passage"](kinds: ['passage']in TypeScript) to the fetch to leave memories out. - Questions that need every match (“list every policy that mentions travel”) → see Query and navigate documents as an agent.
- Keep it current from a drive → connect the source in the dashboard instead of uploading by hand.
- Remove a document →
sdk.documents.delete(...)hides it from every fetch at once and can be restored for a while; see Documents.
Troubleshooting
The first question returns nothing- The upload is still being processed. Wait for
searchable, as in step 3. - Check that the fetch uses the scope the files were uploaded at. Files uploaded with a
user_idare not found by a client-scope fetch.
UnsupportedFormatError
- Documents are not enabled on your Instance, or the format is not one of the supported ones.
InsufficientCreditsForDocumentError
- Your balance is below the document’s estimate. The error carries
estimate_creditsandbalance_credits(estimateCreditsandbalanceCreditsin TypeScript).
document_key
- The caller is not allowed to open that original. The citation still names the document, version and section.
- Upload the new file with the same
document_id, then wait until it is searchable. Until then the previous version is served.
Related
- Concepts: Documents · Citations · Memory scopes
- Guides: Query and navigate documents as an agent · Shaping your MACA
- Reference:
memories.create