Chunking & Embeddings
Documents a chunk preview API and embedding pipeline for building a GPT chat knowledge base with FAISS indices.
What this file does
Documents a chunk preview API and embedding pipeline for building a GPT chat knowledge base with FAISS indices.
When to use it
- You need to split documents into chunks before embedding them
- You want to preview chunk boundaries and metadata without committing to an embedding run
- You are building a RAG system that uses FAISS for vector search
- You need to authenticate and call a chunking API with custom parameters
Assumes this stack
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.
What's inside
1 API route, 4 content types, 4 chunking parameters, 3 code examples, 4 embedding endpoints, 1 test command
Change this for your project
- Replace
https://app.laisky.com/with your own server URL - Replace
LaiskyinX-Laisky-User-IdandX-Laisky-Metadata-Nameheaders with your own prefix - Replace
demo-userin the curl examples with your actual user ID
Where it goes
Reference documentation for a retrieval pipeline. Keep with the ingestion or retrieval code it describes.
Worth borrowing
- Offer a chunk preview endpoint separate from the embedding pipeline so users can inspect segmentation before committing
- Use metadata_name as a stable prefix for chunk sources to keep references predictable across uploads
Related Documents
SUMMARY
Proposes three on-prem AI architectures, modular, hybrid, and fully local RAG, with hardware specs and vendor lists.
Retrieval & Prompts
Explains how CharMemory's extraction prompt and Vector Storage settings determine memory retrieval quality in SillyTavern.
App Review Support Guide — Switch2Go
Explains an AAC app's accessibility permissions, hardware needs, and reviewer walkthrough to pass App Store review.
RFC-BLite: High-Performance Embedded Document Database for .NET
Specifies an embedded document database for.NET with zero-allocation I/O, C-BSON format, and ACID transactions.