How to Filter by Tags
Learn how to use tags to restrict searches and chats to specific documents.
Problem
You have many documents in the Knowledge Base and want to search only in a specific subset.
Solution
Use the tag_names or tag_ids filters in your requests.
Filter by Tag Name
curl -X POST https://api-integrations.snackprompt.com/v1/kb/search \
-H "Content-Type: application/json" \
-H "x-api-key: YOUR_API_KEY" \
-d '{
"query": "vacation policy",
"filters": {
"tenant_id": "your-tenant-id",
"tag_names": ["HR", "Policies"]
},
"limit": 5
}'Filter by Tag ID
Understanding the Logic
Multiple Tags = OR
When you provide multiple tags, the API uses OR logic:
Returns documents that have the tag "Marketing" OR "Sales".
Tags + Other Filters = AND
When combining tags with other filters, the logic is AND:
Returns:
source= "document" AND(
tag_namescontains "Marketing" OR "Sales")
Use Cases
Search in a Specific Category
Search in Multiple Departments
Directed Chat
Use tags in chat to direct the context:
The AI will only use documents with these tags as context.
Where Do Tags Come From?
Tags are defined in the SnackPrompt platform and inherited during ingestion:
The final item will have all tags combined (no duplicates).
Tips
1. Use tag_names for Readability
2. Don't Overdo the Filters
3. Test First with Search
Before using tags in chat, test with search to verify it finds results:
Related
Last updated
Was this helpful?