Skip to content

Latest commit

 

History

History
193 lines (165 loc) · 10.7 KB

HOSTING.md

File metadata and controls

193 lines (165 loc) · 10.7 KB

Hosting vectara-answer

This guide provides specific instructions to help you host your vectara-answer application on one of the popular hosting providers. We will describe how to deploy the default version of vectara-answer that utilizes the .env file locally as well as using a Docker container.

We keep adding new hosting providers regularly — please let us know if you need instructions for a hosting provider that is not yet included.

Overview

To run a hosted version of vectara-answer you would need to have two files: .env and queries.json.

To prepare the .env file, which combines the information from config.yaml and secrets.toml, perform the following:

  1. cd to the main vectara-answer folder, where your secrets.toml file resides
  2. Execute the folllowing command:

python3 docker/prepare_config.py /path/to/<YOUR-CONFIG-FOLDER> <PROFILE>.

The prepare_config.py script accepts two arguments

  • The first is the path to your configuration folder that contains the config.yaml and queries.json files.
  • The <PROFILE> refers to the profile name you used in secrets.toml. If you didn't create a new profile, it likely is called default.

At the end of this process, you should have two files ready to go:

  1. .env in the main vectara-answer folder, generated by the above python3 command
  2. queries.json, in your original configuration folder, that specifies the queries for your application.

Render

Deploy to Render using the Render Dashboard

To deploy the application on Render, using the .env and queries.json file you have ready, please follow these steps:

  1. Sign Up/Log In: If you don't have a Render account, you'll need to create one. If you already have one, just log in.
  2. Create New Service: Once you're logged in, click on the "New" button usually found on the dashboard and select "Web Service".
  3. Choose "Deploy an existing image from a registry" and click "Next"
  4. Specify Docker Image: In the "Image URL" fill in "vectara/vectara-answer" and click "Next"
  5. Choose a name for your deployment (e.g. "vectara-answer"), and if you need to pick a region or leave the default. Then pick your instance type.
  6. Click "Create Web Service"
  7. Click "Environment", then "Add Secret File": name the file .env, and copy the contents of your local .env file
  8. Now click "Add Secret File" again and this time name the file queries.json, and copy the contents of your local queries.json file
  9. Click "Settings" and go to "Docker Command" and click "Edit", the put in the following command:

/bin/sh -c cp /etc/secrets/queries.json ./build/ && cp /etc/secrets/.env ./ && node server/index.js

Then click "Save Changes", and your application should now be deployed.

Deploy to Render Using Render API

Render provides APIs to manage its services, which allow us to deploy vectara-answer directly using an API. If you customize the code of Vectara-Answer and store the resulting codebase on a GitHub repo, then this is a useful way to deploy directly from that repository.

The following describes the steps to deploy vectara-answer from a GitHub repo using the Render API:

  1. Create API Key: Login to your account, go to 'Account Settings' and create an API Key. Checkout the Render Docs for more information.

  2. Check out the Render Create Service API and fill in the 'body params' as follows.

    Field Descriptions:

    • type (string): Type of service, choose the type 'web_service'.
    • ownerID (string): your Render account ID. See Owner APIs for more details.
    • name (string): Name for the service.
    • autoDeploy (string): Choose 'yes' to deploy the created service.
    • repo (string): GitHub url of the vectara-answer repository, for example: https://github.com/vectara/vectara-answer.
    • branch (string): The branch to deploy. If you create a custom branch on a fork, you can specify it here. Otherwise choose main.
    • envVars (array of objects): Env variables to used by vectara-answer. This is an array of key/value pairs for all environment variables as they show in .env. See below for more details.
    • serviceDetails (object): Deployment details of the service.
      • env (string): Runtime env, choose node.
      • plan (string): Render subscription plan. App is deployed in Dev mode and 2GB ram would enough.
      • envSpecificDetails (object): Details how to build/start the service.
        • buildCommand (string): npm run build
        • startCommand (string): npm run start
  3. Now that you have all the parameters, you can use Node to run the deployment command as follows:

  • create a JS file called command.js. Replace the owner ID with your Render user ID, and the API key with your Render API key.
    const axios = require('axios');
    const payload = JSON.stringify({
    type: 'web_service',
    autoDeploy: 'yes',
    serviceDetails: {
        pullRequestPreviewsEnabled: 'no',
        env: 'node',
        envSpecificDetails: {buildCommand: 'npm install', startCommand: 'npm run start'},
        plan: 'standard'
    },
    name: Vectara Docs,
    ownerId: <ownerId>,
    repo: 'https://github.com/vectara/vectara-answer',
    branch: 'main',
    envVars:  [
        {key: 'REACT_APP_corpus_id', value: '1'},
        {key: 'REACT_APP_customer_id', value: '1366999410'},
        {key: 'REACT_APP_api_key', value: 'zqt_UXrBcnI2UXINZkrv4g1tQPhzj02vfdtqYJIDiA'},
        {key: 'REACT_APP_endpoint', value: 'api.vectara.io'},
        {key: 'REACT_APP_app_title', value: 'Vectara Docs Search'},
        {key: 'REACT_APP_search_title', value: 'Vectara Docs Search'},
        {key: 'REACT_APP_search_description', value: 'All of Vectara\'s Platform Documentation'},
        {key: 'REACT_APP_questions', value: JSON.stringify(["How do I enable hybrid search?","How is data encrypted?","What is a textless corpus?","How do I configure OAuth?"])},
        {key: 'REACT_APP_enable_source_filters', value: 'False'},
        {key: 'REACT_APP_summary_default_language', value: 'eng'},
        {key: 'REACT_APP_summary_num_sentences', value: '3'},
        {key: 'REACT_APP_summary_num_results', value: '7'}
    ]
    })
    const url = 'https://api.render.com/v1/services'
    const headers = {
      headers: {
        'Authorization': 'Bearer <API Key>',
        'Content-Type': 'application/json'
      }
    }

    axios.post(url, payload, headers)
     .then(response => {
         console.log(JSON.stringify(response.data))
     })
     .catch(error => {
         console.log(JSON.stringify(error))
     })
  • Execute node command.js

This would create and deploy the vectara-answer service on Render. You can visit the API docs for more information.

Note that this deployment mode pulls the latest docker container image from docker-hub.

Deploy Docker to Render using Render API

The following describes the steps to deploy vectara-answer docker image using the Render API:

  1. Create API Key: Login to your account, go to 'Account Settings' and create an API Key. Checkout the Render Docs for more information.

  2. Create the .env and queries.json file using

  3. Check out the Render Create Service API and fill in the 'body params' as follows.

    Field Descriptions:

    • type (string): Type of service, choose the type 'web_service'.

    • ownerID (string): your Render account ID. See Owner APIs for more details.

    • name (string): Name for the service.

    • autoDeploy (string): Choose 'yes' to deploy the created service.

    • image (object): Information about the docker image.

      • ownerId (string): Render account ID.
      • imagePath (string): Path to the Image. For example 'vectara/vectara-answer'. You can provide custom image as well if you have forked the repo.
    • secretFiles (array of objects): Files to be used by vectara-answer. This is an array of key/value pairs of name and contents of file. See below for more details.

    • serviceDetails (object): Deployment details of the service.

      • env (string): Runtime env, choose image. For more detail prebuilt images.
      • plan (string): Render subscription plan. 512 MB ram would be enough to run the App.
      • envSpecificDetails (object): Details how to build/start the service.
        • dockerCommand (string): Command to be used by docker. See below for more details.
    • create a JS file called command.js. Replace the owner ID with your Render user ID, and the API key with your Render API key.

     const axios = require('axios');
     const url = 'https://api.render.com/v1/services'
     const headers = {
     headers: {
       'Authorization': 'Bearer <API Key>',
       'Content-Type': 'application/json'
     }
     }
     const payload = JSON.stringify({
       type: "web_service",
       autoDeploy: "yes",
       image: {ownerId: <ownerId>, imagePath: 'vectara/vectara-answer'},
       serviceDetails: {
       pullRequestPreviewsEnabled: "no",
       env: "image",
       envSpecificDetails: {
       dockerCommand: '/bin/bash -c cp /etc/secrets/queries.json ./build/ && cp /etc/secrets/.env ./ && node server/index.js'
       },
       plan: "starter"
       },
       name: "vecatra docker",
       ownerId: <ownerId>,
       secretFiles: [
       {
       // local .env file content
       name: ".env",
       contents: "corpus_id=1\ncustomer_id=1366999410\napi_key=zqt_UXrBcnI2UXINZkrv4g1tQPhzj02vfdtqYJIDiA\nendpoint=api.vectara.io\napp_title=Vectara Docs Search\nsearch_title=Vectara Docs Search\nsearch_description=All of Vectara's Platform Documentation\nenable_source_filters=False\nsummary_default_language=eng\nsummary_num_sentences=3\nsummary_num_results=7\n"
       },
       {
       // local queries.json content
       name: "queries.json",
       contents: JSON.stringify({questions: [ "How do I enable hybrid search?","How is data encrypted?","What is a textless corpus?","How do I configure OAuth?"]})
       }
       ]
     })
    
     axios.post(url, payload, headers)
       .then(response => {
       console.log(JSON.stringify(response.data))
     })
       .catch(error => {
       console.log(JSON.stringify(error))
     })
    
    • Execute node command.js

Important

You can't create free-tier services with the Render API. Please check out the Render plans for more details.