Skip to content

HTTP API

Search documents

POST
/v1/search
curl --request POST \
--url https://sergo.example.com/v1/search \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "query": "example", "limit": 10, "offset": 0, "filter": { "folder_ids": [], "document_ids": [] } }'

Searches the text of the documents the key can read, and the file names. Returns the best passage of each document, best first, with up to 3 more passages of the same document. Each passage has its page, and its section heading in Word files. next_offset says where the next page starts when there are more.

Only processed documents are searched — see indexed on a document.

Media typeapplication/json
SearchRequest
object
query
required
Query

What to look for — plain words or a question

string
limit
Limit

How many documents to return, up to 50

integer
default: 10
offset
Offset

Skip this many documents — next_offset from the last response gives the next page

integer
0 <= 150
filter

Narrow the search. It can’t reach past what the key can read

Any of:
SearchFilter
object
folder_ids
Folder Ids

Only these folders, and the folders inside them

Array<string>
default:
document_ids
Document Ids

Only these documents

Array<string>
default:

Successful Response

Media typeapplication/json
SearchResponse
object
results
required
Results

One per document, best first

Array<object>
SearchResult
object
document
required
SearchDocument
object
id
required
Id
string
name
required
Name
string
folder_path
required
Folder Path

Its folder, starting with the owner’s name: Ava Bennett's documents/Handbook

string
chunk_id
required
Chunk Id

The id of this document’s best passage

string
quote
required
Quote

The passage that matched

Any of:
string
page
required
Page

The page it is on

Any of:
integer
heading
required
Heading

The heading of its section, in Word files

Any of:
string
view
required
View

Its page may hold a figure, chart or table that the text misses

boolean
page_estimated
required
Page Estimated

page is an estimate, for a file without pages of its own

boolean
scores
required
Scores

score sets the order — only the order matters, not the number. lexical_rank and dense_rank are its place by keywords and by meaning, when it was found that way. Other keys depend on the index

object
key
additional properties
number
passages
required
Passages

Up to 3 more passages of the same document that ranked, best first

Array<object>
default:
SearchPassage
object
chunk_id
required
Chunk Id
string
quote
required
Quote

The passage that matched

Any of:
string
page
required
Page

The page it is on

Any of:
integer
heading
required
Heading

The heading of its section, in Word files

Any of:
string
view
required
View

Its page may hold a figure, chart or table that the text misses

boolean
page_estimated
required
Page Estimated

page is an estimate, for a file without pages of its own

boolean
scores
required
Scores

score sets the order — only the order matters, not the number. lexical_rank and dense_rank are its place by keywords and by meaning, when it was found that way. Other keys depend on the index

object
key
additional properties
number
next_offset
required
Next Offset

Pass as offset for the next page — null when there are no more

Any of:
integer
steps
required
Steps

What the search did, for people to read

Array<object>
SearchStep
object
name
required
Name
string
detail
required
Detail
string
warnings
required
Warnings

filter_outside_scope: the filter names nothing the caller can read, so nothing was searched

Array<string>
default:
modes
required
Modes

How it searched: by keywords, and by meaning when the install has an embedding model

Array<string>
Allowed values: lexical dense

Example

{
"modes": [
"lexical"
],
"results": [
{
"chunk_id": "9fHc2RxN",
"document": {
"folder_path": "Ava Bennett's documents/Handbook",
"id": "4kTq8Wmz",
"name": "Leave policy.pdf"
},
"page": 4,
"page_estimated": false,
"passages": [
{
"chunk_id": "Bv7Lq3Ps",
"page": 5,
"page_estimated": false,
"quote": "Table 2 shows the carry-over limits by grade.",
"scores": {
"lexical_rank": 3,
"score": 0.61
},
"view": true
}
],
"quote": "Unused annual leave carries over to the next year, up to five days.",
"scores": {
"lexical_rank": 1,
"score": 0.94
},
"view": false
}
],
"steps": [
{
"detail": "key scope — 2 folders (including children)",
"name": "Scope"
},
{
"detail": "default (postgres)",
"name": "Index"
},
{
"detail": "12 passages by keywords",
"name": "Matched"
}
],
"warnings": []
}

Validation Error

Media typeapplication/json
RequestError
object
code
required
Code
string
Allowed value: invalid_request
message
required
Message

What was wrong, field by field

string

Example

{
"code": "invalid_request"
}