Skip to main content
Version: 2.0

API Recipes

Explore common API patterns and use cases for building with Vectara. Each recipe shows complete request and response examples you can adapt for your application.

New to Vectara?

Start with the Developer Quickstart for a fast 5-minute introduction to the basics.

How to use these recipes​

These examples demonstrate real-world patterns for working with the Vectara API:

Ready to explore? Each recipe includes complete code examples with explanations.

Search for answers in a corpus​

Use case: Query an existing corpus and get AI-generated answers with context.

In this example, you have a corpus with uploaded data from an Employee Handbook. You want to ask, "How much PTO is offered to employees each year?"

To issue the cURL command in the example, you input the following field values:

  • x-api-key = YOUR_API_KEY
  • corpus_key = employee-handbook
  • query = How much PTO is offered to employees each year?

Example cURL command​

This example queries the corpus with the question about annual PTO.

VECTARA API QUERY

Code example with bash syntax.
1

Example JSON response​

Let’s take a closer look at the first response:

EXAMPLE JSON RESPONSE

Code example with json syntax.
1

The example API call provided the following response:

"Employee Handbook PTO is 20 days a year for all new employees. Employees earn more vacation days per year of service up to 5 extra days. Example: Once you begin your 5th year, you now have 25 vacation days."

The result answers the question and returns additional details about the query, such as the language, section, and offset.

Let's take a look at some other API calls that you can make.


Add content to a corpus​

Use case: Upload files or index structured documents into an existing corpus.

You can add content to a corpus in two ways: upload files (PDF, Word, etc.) or index structured documents with JSON. Choose the method that fits your data format.

You need to input the following information:

  • x-api-key
  • corpus_key
  • File path (for file upload) or document content (for direct indexing)

Option 1: Upload a file​

In this example, you have a local doc.rtf file that you want to upload the corpus with the corpus_key as employee-handbook:

UPLOAD FILE TO CORPUS

Code example with bash syntax.
1

Example JSON response​

The file uploads successfully and you get the following response:

UPLOAD FILE RESPONSE

Code example with json syntax.
1

Option 2: Index a document directly​

If you don't have a file to upload, you can create a document directly with text content:

INDEX DOCUMENT WITH CONTENT

Code example with bash syntax.
1

Query with result limits​

Use case: Control how many search results are returned and processed.

In this example, you want to search for "technology" and limit the results to 50, then use those results for generating a summary.

Example cURL command​

QUERY WITH 50 RESULTS

Code example with bash syntax.
1

Example JSON response with 5 results​

RESPONSE WITH 5 RESULTS

Code example with json syntax.
1

List and delete corpora​

Use case: Manage your corpora by listing, filtering, and deleting them.

In this example, you'll list all corpora that contain "handbook" in the name, then delete a specific corpus.

  1. Execute the following curl command to list the corpora:

LIST CORPORA WITH FILTER

Code example with bash syntax.
1?

You get the following response:

LIST CORPORA RESPONSE

Code example with json syntax.
1
  1. Execute the following curl command to delete a specific corpus with corpus_key = 2025-handbook.

DELETE CORPUS

Code example with bash syntax.
1?

You get the following response:

DELETE CORPUS RESPONSE

Code example with json syntax.
1
  1. Execute the curl command from Step 1 again and the corpus you deleted no longer exists.