Chunking & Embeddings
This guide walks through the two building blocks of the GPT chat knowledge base:
Chunking & Embeddings
This guide walks through the two building blocks of the GPT chat knowledge base:
- Chunking – turning raw documents or text snippets into small, referenceable sections.
- Embeddings – storing those chunks inside a FAISS index so the conversational agent can search them.
The latest release introduces a dedicated chunk-only API. You can now preview how material will be segmented before deciding to embed it. All previously shipped embedding capabilities continue to work without any changes.
This server is running at https://app.laisky.com/ and is available to all registered users.
Authentication
Most endpoints in the GPT chat service use the same lightweight authentication scheme:
Authorization: Bearer <app-key>X-Laisky-User-Id: <uid>(optional, defaults to the hashed app key)X-Laisky-User-Is-Free: true|false(absence orfalsemarks the account as paid)X-Laisky-Openai-Api-Base: https://api.openai.com/(optional override)
Clients that only need chunk previews can reuse these headers; no additional scopes are required.
Chunk Preview API
- Route:
POST /gptchat/chunks - Purpose: Split plain text or supported document formats (PDF, Word, PowerPoint, Markdown, HTML, TXT) into chunks and inspect the metadata that would later be embedded.
- Compatibility: Existing embedding endpoints (
/gptchat/files,/gptchat/ctx/...) remain unchanged.
Accepted payloads
| Content type | Description |
|---|---|
application/json | Provide text directly as a string. Optional fields: metadata_name, chunk_size, chunk_overlap, max_chunks. |
multipart/form-data | Include a file field for binary uploads and/or a text field. You may also pass metadata_name, chunk_size, chunk_overlap, max_chunks as simple form fields. |
text/* | Raw text body. Optional X-Laisky-Metadata-Name header supplies the source name. |
| other binary types | Send the file body as-is and supply X-Laisky-File-Name (with extension) plus optional X-Laisky-Metadata-Name. |
Chunking parameters
chunk_size– Maximum tokens per chunk. Defaults to500.chunk_overlap– Token overlap between adjacent chunks. Defaults to30. Must be smaller thanchunk_size.max_chunks– Cap on total chunks returned. Defaults to600for free users and10000for paid users. The service automatically clips any larger request to your account tier.metadata_name– Prefix for the generatedsourcemetadata. When omitted, the service uses the file name (for uploads) orinline-text.
JSON example (inline text)
curl -X POST "${HOST}/gptchat/chunks" \
-H "Authorization: Bearer ${APP_KEY}" \
-H "X-Laisky-User-Id: demo-user" \
-H "Content-Type: application/json" \
-d '{
"text": "My doc intro...",
"metadata_name": "project-notes",
"chunk_size": 800,
"chunk_overlap": 40
}'
Multipart example (PDF upload)
curl -X POST "${HOST}/gptchat/chunks" \
-H "Authorization: Bearer ${APP_KEY}" \
-H "X-Laisky-User-Id: demo-user" \
-F "file=@/path/to/report.pdf" \
-F "metadata_name=report-2025" \
-F "chunk_size=600" \
-F "chunk_overlap=60"
Raw binary example (HTML body)
curl -X POST "${HOST}/gptchat/chunks" \
-H "Authorization: Bearer ${APP_KEY}" \
-H "X-Laisky-File-Name: public.html" \
-H "X-Laisky-Metadata-Name: public-site" \
--data-binary @page.html
Response payload
{
"chunks": [
{
"text": "...",
"metadata": {
"source": "project-notes?chunk=1"
}
}
],
"total": 4,
"chunk_size": 800,
"chunk_overlap": 40,
"max_chunks": 600,
"source": "project-notes",
"origin": "text"
}
chunkscontains the raw text plus metadata that downstream embedding calls reuse.originindicates whether the request came fromtextorfileinput.sourceis the canonical prefix applied to each chunk`s metadata.max_chunksreflects the resolved cap after applying account limits.
Errors are returned as 400 responses with a descriptive message when inputs are invalid (e.g., unsupported extension, chunk overlap larger than the size, missing file name for binary uploads).
Embedding pipeline (unchanged)
Once you are satisfied with the chunk preview, continue with the existing endpoints:
- Upload & Index –
POST /gptchat/files- Upload encrypted datasets for private indices. The worker encrypts the source document, builds embeddings, and stores everything in Minio.
- Manage datasets –
GET /gptchat/files- List uploaded datasets and the subset currently active in the user cache.
- Build chatbot indices –
POST /gptchat/ctx/build- Combine multiple datasets into an interactive chatbot index.
- Query embeddings –
GET /gptchat/ctx/chatorGET /gptchat/query/query- Retrieve answers from private or prebuilt indices.
All of these endpoints continue to rely on the same metadata emitted by the chunk preview service, so no client-side adjustments are required.
Best practices
- Use the preview API before uploading large files to ensure the chunk count fits within your quota.
- Keep
metadata_namestable across uploads so references remain predictable. - Free accounts can request a smaller
max_chunksto trim responses without waiting for the auto-limit. - After chunking, you can reuse the same payload with
embedding_fileworkflows to build new datasets.
Local testing
- Run
pytest tests/test_chunk_preview.pyto exercise the chunk-only endpoint. - Existing tests (
tests/test_vector_store.py, etc.) still validate serialization of embedding stores. - The test suite mocks storage credentials, so no external services are required.
Related Documents
SUMMARY
permalink: ai-implementation
Retrieval & Prompts
Retrieval quality depends on two things: **what the extraction prompt produces**, and **how Vector Storage is configured**. Most people start with Vector Storage settings — but the bigger lever is the prompt. A well-structured memory block retrieves accurately even with default settings. A poorly structured one won't retrieve well no matter how much you tune.
App Review Support Guide — Switch2Go
Switch2Go is an **AAC (Augmentative and Alternative Communication)** app designed specifically for users with **Cerebral Visual Impairment (CVI)**. It allows non-verbal or communication-impaired users to compose and speak phrases entirely hands-free using:
Core principles
You are an AI engineer designed to help users use Jina AI Search Foundation API's for their specific use case.