Documents

Import, export, create, update, and delete documents in a collection. Torque supports four ingestion paths with different throughput and use-case trade-offs.

Ingestion Methods

MethodBest For
HTTP JSONLSmall updates, Typesense client compatibility, ad-hoc imports
TCP Binary ProtocolLive streaming from databases, real-time sync pipelines
TQBF Binary File UploadBulk loading, ETL pipelines, data distribution, initial imports
Segment FilesScheduled rebuilds: a whole collection indexed off the server, installed without indexing

The first three send documents for the server to index. The fourth sends a collection that is already indexed - see Segment Files below - which is the path to use when you rebuild a large collection on a schedule.

On a 309,236-document dataset with 67 fields, Torque's TCP binary ingest completes in 6.3 seconds (49K docs/s), timed until every document is searchable - 7.7x faster than Typesense on the same hardware. TQBF file upload handles even larger datasets in a single HTTP POST with no per-document JSON parsing.

Import Documents (HTTP JSONL)

Import documents in JSONL format (one JSON object per line):

POST /collections/products/documents/import
Content-Type: text/plain
X-TYPESENSE-API-KEY: YOUR_API_KEY

{"id": "1", "title": "Running Shoes", "price": 89.99, "category": "Footwear"}
{"id": "2", "title": "Hiking Boots", "price": 149.99, "category": "Footwear"}
{"id": "3", "title": "Laptop Stand", "price": 49.99, "category": "Electronics"}

The response returns one JSON result per line, indicating success or failure for each document:

{"success": true}
{"success": true}
{"success": true}

Import supports four actions via the action query parameter:

ActionDescription
create (default)Create new documents. Fails if the id already exists.
upsertCreate or replace. If a document with the same id exists, it is replaced.
updateMerge fields into existing documents. Only specified fields are updated.
emplaceCreate when the id is new; merge fields when it exists.
POST /collections/products/documents/import?action=upsert

The same action values apply to single-document POST /collections/{name}/documents?action= requests. Add return_doc=true to imports to echo the indexed document in each result line.

Performance: HTTP JSONL import is suitable for small to medium datasets. For large-scale ingestion, use the TCP binary protocol, which reaches 49K docs/s.

Import Documents (TCP Binary Protocol)

The TCP binary protocol streams documents over a persistent connection in a compact binary encoding, bypassing JSON parsing overhead. It runs on port 8109 by default and supports two ingestion modes:

Batch Mode

Stream a large volume of documents, then commit to trigger a full index rebuild. Best for initial loads and periodic bulk updates where all data arrives at once.

  1. Client sends StartIngest (collection name, mode=batch)
  2. Client sends one or more DocBatch messages (e.g., 5,000 docs per batch)
  3. Server acknowledges each batch with a sequence number
  4. Client sends Commit - server rebuilds the full index atomically

Realtime Mode

Instant upserts and deletes without a commit step. Each write group is indexed as a small segment and is searchable at once; a write-ahead log makes it durable before it is acknowledged, and replaced documents are hidden by deletion masks. Best for live sync from databases.

  1. Client sends StartIngest (collection name, mode=realtime)
  2. Client sends Upsert messages - each document is searchable immediately
  3. Background merges consolidate the small segments, from their sections rather than by decoding every document again

See TCP Protocol for the full wire format specification. Client libraries are available for .NET, Python, Go, Java, and Node.js.

Import Binary File (TQBF)

A binary import file is the fastest way to hand the server documents it still has to index. The documents are pre-encoded in the binary wire format and compressed, so the server parses no JSON and compresses nothing at import time. To skip the server's indexing as well, build segment files instead.

File Format (TQBF v2)

A binary import file has a 24-byte header followed by a compressed payload of concatenated serialized documents:

OffsetSizeDescription
04 bytesMagic: TQBF (ASCII)
44 bytesVersion: 2 (little-endian u32)
84 bytesDocument count (little-endian u32)
124 bytesFlags: bit 0 = LZ4, bit 1 = ZLib
168 bytesUncompressed payload size (little-endian u64)
24N bytesCompressed concatenated binary documents

The uncompressed-size hint lets the server size its decompression buffer exactly once instead of growing it. The 16-byte v1 header, which omitted that size, is still accepted. torque-admin export-binary writes LZ4; both compressions are read.

Three kinds of .tqbf file

Three different things use the .tqbf extension, and none is interchangeable with the others. Passing one to the wrong command fails rather than producing a wrong collection.

Produced byIsConsumed by
TorqueBinaryWriter, torque-admin export-binaryA binary import file (v2 above): documents onlyimport-binary, and the server indexes them
TqbfDocsWriter (.NET)A docs-only v6 file: a schema and records, as build inputtorque-admin build, which produces segments
torque-admin build, TqbfSegmentBuilder (.NET)Finished segments: documents and their indexesupload, and the server maps them without indexing

Upload via HTTP

POST /collections/products/documents/import-binary
Content-Type: application/octet-stream
X-TYPESENSE-API-KEY: YOUR_API_KEY

[binary TQBF file contents]
# Upload with curl
curl -X POST -H "X-TYPESENSE-API-KEY: KEY" \
  "http://localhost:8108/collections/products/documents/import-binary" \
  --data-binary @data.tqbf

Create TQBF Files

TQBF files can be created using the SDK binary writers or torque-admin:

# Export existing collection to TQBF file
torque-admin --api-key KEY export-binary my_collection -o data.tqbf

# Import TQBF file into a collection
torque-admin --api-key KEY import-binary my_collection -f data.tqbf

Each SDK includes a binary writer class for creating TQBF files programmatically:

SDKClass
.NETTorqueBinaryWriter - docs
PythonTorqueBinaryFileWriter - docs
GoNewBinaryFileWriter - docs
JavaTorqueBinaryWriter - docs
Node.jsTorqueBinaryWriter - docs

When to use TQBF vs TCP: Use TQBF for offline bulk loads, ETL pipelines, and data distribution where you can pre-encode files ahead of time. Use TCP binary streaming for live sync from databases where documents arrive continuously. Both avoid per-document JSON parsing; TCP streaming reaches 49K docs/s.

Segment Files

A full reindex through a document API asks the server to receive, parse and index every document while it is also answering searches. For a large collection replaced on a schedule, that work can take hours on the machine serving your users.

Segment files move the build somewhere else. You index the collection on the machine that holds the data, or on a build machine, and send the server a finished collection: documents and indexes together in immutable files. The server verifies the checksums, writes the files as received, maps them and switches an alias. It does no indexing for that collection.

Source database -> Build segment files -> Upload and validate -> Switch alias -> Serve searches

Building and publishing

# Build finished segments from a docs-only file written by TqbfDocsWriter
torque-admin build docs.tqbf -o out/

# Upload them as a new collection and point the alias at it
torque-admin --api-key KEY upload my_collection_20261107 -f out/ --alias my_collection

The previous collection is kept, so the alias can be switched back if the new one is wrong. Add --drop-old to remove it once the switch is made. Because the new collection exists under its own name before the alias moves, you can query and validate it while users are still served by the old one.

The .NET client can skip the intermediate file and build segments straight from your application objects with TqbfSegmentBuilder, or write the docs-only build input with TqbfDocsWriter. build runs offline and needs no server; --level sets the zstd level of the stored documents (default 19), and --transport additionally stores sections that zstd shrinks by 10% or more as zstd frames, which the server restores on upload.

Segment format (TQBF v6)

Segment files are a different format from the binary import file above, though they share the extension. One file is one segment: a 64-byte header, a section table, then sections aligned so each is read in place from the mapped file, with an xxh3 checksum per section. Nothing is deserialized onto the heap at load time except a few KB of field registry, so RAM holds only the pages the operating system keeps hot.

Segment files are version 6. A file of any other version is refused rather than migrated, so the native segment builder and the .NET client must be rebuilt together with the server. The full specification is docs/tqbf-segment-format.md in the repository.

What the offline builder does not do: it needs an explicit schema, and it does not build vector fields, generate embeddings or discover dynamic fields. Use the server's HTTP document import for a collection that needs any of those.

Export Documents

Export all documents in a collection as JSONL:

GET /collections/products/documents/export
X-TYPESENSE-API-KEY: YOUR_API_KEY

The response streams one JSON document per line.

Create a Document

POST /collections/products/documents
Content-Type: application/json
X-TYPESENSE-API-KEY: YOUR_API_KEY

{
  "id": "4",
  "title": "Wireless Mouse",
  "price": 29.99,
  "category": "Electronics"
}

Get a Document

GET /collections/products/documents/4
X-TYPESENSE-API-KEY: YOUR_API_KEY

Update a Document

Partially update a document by merging fields:

PATCH /collections/products/documents/4
Content-Type: application/json
X-TYPESENSE-API-KEY: YOUR_API_KEY

{"price": 24.99}

Update by Filter

Apply a partial update to every document matching a filter in one request. The patch is validated against the schema before anything is written - an invalid patch is rejected outright rather than partially applied:

PATCH /collections/products/documents?filter_by=category:=Electronics
Content-Type: application/json
X-TYPESENSE-API-KEY: YOUR_API_KEY

{"in_stock": false}

The response reports the number of updated documents.

Delete a Document

DELETE /collections/products/documents/4
X-TYPESENSE-API-KEY: YOUR_API_KEY

Delete by Filter

DELETE /collections/products/documents?filter_by=in_stock:false
X-TYPESENSE-API-KEY: YOUR_API_KEY

filter_by is required. To delete all documents, pass truncate=true explicitly - a bare bulk delete returns 400 as a safety guard.

Document IDs

Every document has a string id field that uniquely identifies it within the collection. If you don't provide an id during import, Torque auto-generates one.

Compaction

After many realtime upserts and deletes, the index may accumulate overlay data. Trigger compaction to consolidate:

POST /collections/products/documents/compact
X-TYPESENSE-API-KEY: YOUR_API_KEY

Compaction also runs automatically based on the --compaction-interval-secs and --compaction-memory-threshold-percent settings.

Suspend and Resume

Pause realtime ingestion for a collection (e.g., during maintenance):

# Suspend ingestion
POST /collections/products/suspend
X-TYPESENSE-API-KEY: YOUR_API_KEY

# Resume ingestion
POST /collections/products/resume
X-TYPESENSE-API-KEY: YOUR_API_KEY

torque-admin CLI

The torque-admin binary provides command-line data management. All commands require --api-key or the TORQUE_API_KEY environment variable.

# List collections
torque-admin --api-key KEY collections

# Export collection (schema + JSONL)
torque-admin --api-key KEY export my_collection

# Import collection via TCP binary (batch mode - full rebuild)
torque-admin --api-key KEY import my_collection --batch-size 5000

# Import collection via TCP binary (realtime mode - upserts into the collection's segments)
torque-admin --api-key KEY import my_collection --mode realtime

# Export to TQBF binary import file (LZ4 compressed)
torque-admin --api-key KEY export-binary my_collection -o data.tqbf

# Import from TQBF binary import file
torque-admin --api-key KEY import-binary my_collection -f data.tqbf

# Delete documents by ID (realtime mode only)
torque-admin --api-key KEY delete my_collection --ids id1,id2,id3

# Build segment files from a docs-only TQBF file (offline, no server needed)
torque-admin build docs.tqbf -o out/

# Upload segments as a new collection, switch an alias, drop the old collection
torque-admin --api-key KEY upload my_collection_20261107 -f out/ --alias my_collection --drop-old

build is the only subcommand that needs no API key, because it never talks to a server. --drop-old requires --alias.