Skip to main content
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.
An assistant that answers from your own documents: an HR handbook, a returns policy, a security policy. Every answer comes with the passage it was drawn from and a way to open the original file, so people can check it.

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
Est. build time: 30-40 minutes.

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
If the knowledge belongs to one person or one customer, upload at that scope instead; see Choose a scope.

Architecture at a glance

The model only sees passages Synap returned, so the answer can be traced to a source.

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 no user_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 stable document_id. It is how Synap knows a later upload is the same document.
Synap works out each file’s type from its content. You can also declare one, such as 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 is searchable.

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

To see versions at work, edit 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_id and fetch with sdk.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_id are not found by a client-scope fetch.
The upload is refused with UnsupportedFormatError
  • Documents are not enabled on your Instance, or the format is not one of the supported ones.
The upload is refused with InsufficientCreditsForDocumentError
  • Your balance is below the document’s estimate. The error carries estimate_credits and balance_credits (estimateCredits and balanceCredits in TypeScript).
A source has no document_key
  • The caller is not allowed to open that original. The citation still names the document, version and section.
The answer quotes an old version
  • Upload the new file with the same document_id, then wait until it is searchable. Until then the previous version is served.