Search a collection

Retrieve the passages that best match a query, with scores, to show or to feed into your own model.

POST /v1/{knowledge_id}/search returns the sections (chunks) of the collection's documents that best match a query. No language model writes an answer — use it when you want the passages themselves: to show them, to rank documents, or to give to a model of your own.

Request

FieldTypeDefaultMeaning
querystring—What to search for. Required unless object_ids is given.
num_chunksinteger3How many sections to return, 1–100.
object_idsstring[]all documentsOnly search these documents. An empty list returns no results.
modestringhybridhybrid combines keyword and meaning-based matching; non_hybrid uses meaning only.

Unknown fields are rejected with 422, so a misspelt option fails loudly instead of being ignored.

Python
import os
import requests

API_ROOT = "https://futuresmart.ai/document-intelligence/api"
COLLECTION_ID = os.environ["DOCUMENT_INTELLIGENCE_COLLECTION_ID"]

r = requests.post(
    f"{API_ROOT}/v1/{COLLECTION_ID}/search",
    headers={"x-api-key": os.environ["DOCUMENT_INTELLIGENCE_API_KEY"]},
    json={"query": "late payment fee", "num_chunks": 3},
    timeout=60,
)
r.raise_for_status()
for chunk in r.json()["chunks"]:
    print(f"{chunk['relevance_score']:.2f}  {chunk['file_name']}: {chunk['chunk_text'][:80]!r}")

Response

JSON
{
  "chunks": [
    {
      "id": "9b4c93f6-0e72-5903-bc5a-b5103a75928f",
      "object_id": "b59a5c27-80d5-4d24-818f-3fa50f987670",
      "knowledge_id": "d60416be-8e29-458f-adf9-3a4839059855",
      "file_name": "terms.txt",
      "chunk_text": "File Name: terms.txt\n\nExtracted Text: … Late payments incur a 1.5% monthly fee. …",
      "relevance_score": 1.0,
      "search_method": "hybrid_knowledge_base"
    }
  ]
}
  • chunk_text is the indexed text of the section, prefixed with the file name and any extra context the service added when indexing.
  • relevance_score ranks results within one response. Compare scores inside a response, not across queries.
  • object_id identifies the document; use it to fetch the document's extracted fields or to restrict a later search with object_ids.

Search or chat?

Use search whenUse chat when
You want the passages, not proseYou want a written answer
You run your own model or rankingYou want sources picked and cited for you
You need predictable, fast responsesYou need follow-up questions with memory