Multiple Corpora Query
POSThttps://api.vectara.io/v2/query
Perform a multipurpose query across to retrieve relevant information from one or more corpora and generate a response using Retrieval Augmented Generation (RAG).
- Specify the unique
corpus_key
identifying the corpus to query. Thecorpus_key
is created in the Vectara Console UI or the Create Corpus API definition. When creating a new corpus, you have the option to assign a customcorpus_key
following your preferred naming convention. This key serves as a unique identifier for the corpus, allowing it to be referenced in search requests. For more information, see Corpus Key Definition. - Customize your search by specifying the query text (
query
), pagination details (offset
andlimit
), and metadata filters (metadata_filter
) to tailor your search results. Learn more - Leverage advanced search capabilities like reranking (
reranker
) and opt-in Retrieval Augmented Generation (RAG) (generation
) for enhanced query performance. Generation is opt in by setting thegeneration
property. By excluding the property or by setting it to null, the response will not include generation. Learn more - Specify Vectara's RAG-focused LLM (Mockingbird) for the
generation_preset_name
. Learn more - Use advanced summarization options that utilize detailed summarization parameters such as
max_response_characters
,temperature
, andfrequency_penalty
for generating precise and relevant summaries. Learn more - Customize citation formats in summaries using the
citations
object to include numeric, HTML, or Markdown links. Learn more
For more detailed information, see this Query API guide.
Request
Header Parameters
Possible values: >= 1
The API will make a best effort to complete the request in the specified seconds or time out.
Possible values: >= 1
The API will make a best effort to complete the request in the specified milliseconds or time out.
- application/json
Body
The search query string, which is the question the user is asking.
search object
generation object
Default value: false
Indicates whether the response should be streamed or not.
Indicates whether to save the query to query history.
Default value: false
Indicates whether to enable intelligent query rewriting. When enabled, the platform will attempt to extract metadata filter and rewrite the query to improve search results.
Responses
- 200
- 400
- 403
- 404
A response to a query.
- application/json
- text/event-stream
- Schema
- Example (from schema)
Schema
The summary of the search results.
Possible values: [auto
, eng
, deu
, fra
, zho
, kor
, ara
, rus
, tha
, nld
, ita
, por
, spa
, jpn
, pol
, tur
, vie
, ind
, ces
, ukr
, ell
, heb
, fas
, hin
, urd
, swe
, ben
, msa
, ron
]
Default value: auto
Languages that the Vectara platform supports.
search_results object[]
Indicates the probability that the summary is factually consistent with the results. The system excludes this property if it encounters excessively large outputs or search results.
The rendered prompt sent to the LLM. Useful when creating customer prompt_template
templates.
Possible values: [exceeded_max_input_length_fcs
, intelligent_query_rewriting_failed
]
Non-fatal warnings that occurred during request processing
rewritten_queries object[]
{
"summary": "string",
"response_language": "auto",
"search_results": [
{
"text": "string",
"score": 0,
"part_metadata": {},
"document_metadata": {},
"document_id": "string",
"table": {
"id": "table_1",
"title": "string",
"data": {
"headers": [
[
{
"text_value": "string",
"int_value": 0,
"float_value": 0,
"bool_value": true,
"colspan": 0,
"rowspan": 0
}
]
],
"rows": [
[
{
"text_value": "string",
"int_value": 0,
"float_value": 0,
"bool_value": true,
"colspan": 0,
"rowspan": 0
}
]
]
},
"description": "string"
},
"request_corpora_index": 0
}
],
"factual_consistency_score": 0,
"rendered_prompt": "string",
"warnings": [
"exceeded_max_input_length_fcs"
],
"rewritten_queries": [
{
"corpus_key": "string",
"filter_extraction": {
"query": "string",
"metadata_filter": "string"
}
}
]
}
- Schema
- Example (from schema)
Schema
- StreamSearchResponse
- StreamGenerationChunk
- StreamGenerationEnd
- StreamResponseEnd
- FactualConsistencyScore
- GenerationInfo
- StreamError
Default value: search_results
When the streaming event has the search results, the
type will be search_results
.
search_results object[]
rewritten_queries object[]
Default value: generation_chunk
When the streaming event contains the next chunk of generator output, the
type will be generation_chunk
.
Part of the message from the generator. All summary chunks must be appended together in order to get the full summary.
Default value: generation_end
Then end of generation will be denoted with an object
with the type generation_end
.
Default value: end
Then end of stream will be denoted with an object
with the type end
.
Default value: factual_consistency_score
When the streaming event contains the factual consistency score, the
type will be factual_consistency_score
.
The probability that the summary is factually consistent with the results.
Default value: generation_info
When the streaming event contains the generation information
type will be generation_info
.
The rendered prompt sent to the LLM. Useful when creating customer prompt_template
templates.
View the actual query made to backend that was rephrased by the LLM from the input query.
Default value: error
If the stream errors, an event with type error
will
be sent.
The error messages.
{}
Query request was malformed.
- application/json
- Schema
- Example (from schema)
Schema
field_errors object
The ID of the request that can be used to help Vectara support debug what went wrong.
{
"field_errors": {},
"messages": [
"string"
],
"request_id": "string"
}
Permissions do not allow querying one or more corpora in the request.
- application/json
- Schema
- Example (from schema)
Schema
The messages describing why the error occurred.
The ID of the request that can be used to help Vectara support debug what went wrong.
{
"messages": [
"Internal server error."
],
"request_id": "string"
}
One or more of the corpora were not found.
- application/json
- Schema
- Example (from schema)
Schema
The ID cannot be found.
ID of the request that can be used to help Vectara support debug what went wrong.
{
"id": "string",
"messages": [
"string"
],
"request_id": "string"
}
Authorization: x-api-key
name: x-api-keytype: apiKeyin: header
- curl
- python
- go
- nodejs
- ruby
- csharp
- php
- java
- powershell
- CURL
curl -L -X POST 'https://api.vectara.io/v2/query' \
-H 'Content-Type: application/json' \
-H 'Accept: application/json' \
-H 'x-api-key: <API_KEY_VALUE>' \
--data-raw '{
"query": "Am I allowed to bring pets to work?",
"search": {
"corpora": [
{
"custom_dimensions": {},
"metadata_filter": "doc.title = '\''Charlotte'\'''\''s Web'\''",
"lexical_interpolation": 0.025,
"semantics": "default",
"corpus_key": "my-corpus",
"query": "string"
}
],
"offset": 0,
"limit": 10,
"context_configuration": {
"characters_before": 30,
"characters_after": 30,
"sentences_before": 3,
"sentences_after": 3,
"start_tag": "<em>",
"end_tag": "</em>"
},
"reranker": {
"type": "customer_reranker",
"reranker_name": "Rerank_Multilingual_v1",
"limit": 0,
"cutoff": 0
}
},
"generation": {
"generation_preset_name": "vectara-summary-ext-v1.2.0",
"max_used_search_results": 5,
"prompt_template": "[\n {\"role\": \"system\", \"content\": \"You are a helpful search assistant.\"},\n #foreach ($qResult in $vectaraQueryResults)\n {\"role\": \"user\", \"content\": \"Given the $vectaraIdxWord[$foreach.index] search result.\"},\n {\"role\": \"assistant\", \"content\": \"${qResult.getText()}\" },\n #end\n {\"role\": \"user\", \"content\": \"Generate a summary for the query '\''${vectaraQuery}'\'' based on the above results.\"}\n]\n",
"max_response_characters": 300,
"response_language": "auto",
"model_parameters": {
"llm_name": "gpt4",
"max_tokens": 0,
"temperature": 0,
"frequency_penalty": 0,
"presence_penalty": 0
},
"citations": {
"style": "none",
"url_pattern": "https://vectara.com/documents/{doc.id}",
"text_pattern": "{doc.title}"
},
"enable_factual_consistency_score": true
},
"stream_response": false,
"save_history": true,
"intelligent_query_rewriting": false
}'