“Search only the Project Alpha documents.” “Answer this question using just our compliance files.”That’s what tags give you: a lightweight way to carve your corpus into named groups your app can filter on.
Workspaces, tags, or facets?
All three organise documents, but at different layers. They compose: a file lives in one workspace, can carry several tags, and can be classified with facets.| Workspaces | Tags | Facets | |
|---|---|---|---|
| What it is | A container; every file lives in exactly one | Flat, reusable labels | Typed, hierarchical metadata with a schema |
| A file belongs to | exactly one workspace | many tags, across workspaces | many content types, across workspaces |
| Best for | Isolating teams, customers, tenants | Cross-cutting collections (project, topic) | Precise structured queries |
| Setup cost | Create a workspace | Create a tag | Design a content-type tree |
| Scope a query with | workspace_id | tag_id | content_type / attribute |
| Access control | Yes: API keys can be scoped to a workspace with a per-key role | No: not a permission boundary | No: not a permission boundary |
Project Alpha tag on files that live in both the Engineering and Design workspaces. You can combine tag_id with workspace_id to scope to a tagged collection within a single workspace. The rest of this tutorial covers tags.
Step 1: Create a tag
A tag has aname and a description. Create it once at the company level, then reuse it across as many files as you like.
create_tag.py
201 returns the new tag with its id. Note it down: you’ll use the ID everywhere else.
auto_assign controls who can attach the tag. It defaults to true, meaning LightOn’s AI can assign the tag to matching documents automatically (your description is the signal it matches on, so write it well). Set it to false for a manual-only tag that the system never touches.
Step 2: Find a tag’s ID
Tags are company-scoped, so a teammate may already have created the one you need. List them, optionally filtering by name, to grab the ID.list_tags.py
document_count so you can see how populated a collection is.
Step 3: Assign tags to files
You have three ways to attach tags, depending on timing:- At upload time: pass
tagsin the upload payload. See Uploading & managing files. - Add to an existing file:
POST /api/v3/files/{id}/tags. Adds tags without disturbing the ones already there. - Replace every tag:
PATCH /api/v3/files/{id}with a newtagsarray. This overwrites all existing tags, manual and auto-assigned alike.
add_tags.py
tags array. Duplicate tags are ignored (no error), and newly added tags are marked auto_assigned: false.
Step 4: List files in a collection
Once files are tagged, filter the file listing bytag_id to retrieve a collection.
filter_by_tag.py
tag_id with other filters (extension, workspace_id, total_pages_min) to narrow further.
Step 5: Scope search and ask to a collection
This is where tags earn their keep. BothPOST /api/v3/search and POST /api/v3/ask accept a tag_id array that restricts the query to documents in those collections. Pass several IDs to widen the scope to a union of collections.
Search across a collection:
search_by_tag.py
ask_by_tag.py
tag_id combines with workspace_id (both narrow the corpus together), but is mutually exclusive with file_id.
Step 6: Remove a tag
To take a single file out of a collection, delete that one association. The file and the tag both survive; only the link is removed.remove_tag.py
204 confirms success. The call is idempotent: you get 204 even if the tag wasn’t on the file.
To retire a tag everywhere, DELETE /api/v3/tags/{id}. That removes the tag from every document it was attached to, so use it deliberately.
Next steps
Uploading & managing files
Assign tags at upload time and manage file metadata
Searching documents
Rank passages, then scope the search by tag
Asking questions
Get grounded answers over a tagged collection
Organizing documents with metadata
Step up to typed, structured metadata with facets