Skip to main content

An Unofficial Python SDK and CLI for Vectara's RAG platform

Installation

pip install vektara # Stable
# OR
pip install "git+https://github.com/forrestbao/vektara.git" # Nightly
# OR
# Development mode where local changes are reflected immediately
git clone https://github.com/forrestbao/vektara.git
pip install -e .

Hello, world!

Here are the basic steps in RAG:

  1. Creating a corpus, a collection of documents.
  2. Ingestion: upload documents to a corpus.
  3. Querying: ask questions to the corpus.
from vektara import Vectara

client = Vectara() # get credentials from environment variables

corpus_id = client.create_corpus('founding documents of the US')

client.upload(corpus_id, './test_data/US_Constition.txt')
client.upload(corpus_id, './test_data/Declaration_of_Independence.txt')

client.query(corpus_id, 'What should I do if the government becomes unjust?')

Before you start: credentials

Obtaining Vectara credentials

This client supports authentication in both Vectara's Personal API key and OAuth2. In either case, you need to obtain customer ID as well.

Setting up credentials

Following the convention of OpenAI's client, we recommend setting credentials as environment variables. You can save them as a bash script and simply source it before using the SDK.

export VECTARA_CUSTOMER_ID=123 # Required regardless of the authentication method

# For using Personal API Key to authenticate
export VECTARA_API_KEY=abc

# For using OAuth2 to authenticate
export VECTARA_CLIENT_ID=abc
export VECTARA_CLIENT_SECRET=xyz

# If both API key and OAuth2 credentials are set, the API key supercedes OAuth2.

# optional, if you are using a proxy like LlaMasterKey https://github.com/TexteaInc/LlaMasterKey/
export VECTARA_BASE_URL="http://127.0.0.1:8000/vectara"
export VECTARA_PROXY_MODE=true # Enable proxy mode

Alternatively, you can pass in your credentials as arguments when initializing the client.

Using the Python SDK

Here are the resources to learn the Python SDK:

  1. Reference manual
  2. Crash course
  3. Demos

The SDK supports the following operations. Detailed usages can be found in the reference manual.

  1. Create a corpus
  2. Reset a corpus (cleans out documents in a corpus but keeps the corpus and metadata)
  3. List the documents in a corpus
  4. Add documents to a corpus
    • From local file(s)/folder
    • From a list of chunks (str) without any hierarchy
    • From a nested list of sections hierarchically but you don't control chunking - a section is a list of str's or sections.
  5. Query a corpus
  6. Set filters for a corpus which is a job in a queue
  7. List a job (e.g., filter setting) in a corpus

Using the CLI client

The features in the CLI client are similar to the SDK. To learn the command line usage, run vectara --help.

You must obtain and set up your Vectara credentials as environment variables before using the command line interface.

# create a corpus
vektara create_corpus 'my knowledge base'
# output: corpus_id = 12

# upload a file to the corpus
vektara upload 12 one_file.pdf # corpurs_id = 12

# upload a folder to the corpus
vektara upload 12 ./a_folder_of_documents # corpurs_id = 12

# query the corpus
vektara query 12 'Vectara allows me to search for anything, right?' --top_k=5  # corpurs_id = 12

# reset the corpus
vektara reset_corpus 12 # corpurs_id = 12

The GUI client via Funix

The SDK can be converted into a web interface via Funix. You can drag and drop to add a file to your Vectara corpus.

pip install funix
funix src/vektara/__init__.py

Then you can access the web interface at http://localhost:3000 (the port number maybe different if port 3000 is occupied).

Below please find the screenshots.

Initiate Vectara

Create a corpus

Upload a file

Query the corpus

Known bugs: Funix seems to have some memory leakage issues that the web interface may freeze after uploading a file. If that happens, please kill the process and restart the web interface.

Stylish query results

The query results are typeset Markdown ready to be rendered. A query result includes the following info:

  • A summary with citations and matching scores with respect to the query
  • References cited by the summary
### Here is the answer
To rearrange objects, you can utilize the "direction" attribute in a Funix decorator [1]. Manually resizing and positioning objects can be a tedious and inefficient process [2]. Another approach is to use a collision-free algorithm for auto-layout, where scopes will be resized to fit the objects inside [4]. An example of arranging objects in a column-reverse direction can be seen in the ChatGPT multiturn app [3]. Additionally, organizing your canvas with scopes can help in rearranging objects effectively [5]. Remember to experiment with these methods to find the best arrangement for your specific needs.

### References:

1. From document **funix.md** (matchness=0.673933):
  _...You can change their order and orientation using the "direction" attribute in a Funix decorator...._

2. From document **codepod.md** (matchness=0.65305215):
  _...It is painful and inefficient to resize and position the pods and scopes manually...._

3. From document **funix.md** (matchness=0.6520513):
  _...The example below shall be self-explaining:
A more advanced example is our ChatGPT multiturn app where "direction = "column-reverse"" so the message you type stays at the bottom...._

4. From document **codepod.md** (matchness=0.6495899):
  _...default}alt="Example banner"width="600"/>
After auto-layout, the pods and scopes are organized by a collision-free algorithm, and the scopes will be resized to fit the pods inside...._

5. From document **codepod.md** (matchness=0.6460015):
  _...Organize your Canvas with scopes..._

This SDK/CLI/GUI vs. Vectara's official RESTFul API

  • Type less and more done. No boilerplate code.
  • Copy-and-pastable examples and Jupyter notebooks to jumpstart you.
  • Forget about low-level details, e.g., all metadata fields are automatically set to filterable -- under construction.
  • More ways to interact
    • Command line interface (CLI)
    • GUI powered by [Funix.io]http://Funix.io) for quickly building web apps that ordinary people can use.
  • More features:
    • Upload an entire folder.
    • Stylish Markdown printout for query response (see demo_simple.ipynb).
    • Log user feedback from the GUI in a local SQLite database for evaluating the quality of search and RAG.
    • Pairable with LlamaKey.ai or any API router to manage API keys and throttle requests.

Questions

Contact forrest at vectara dot com

Disclaimer

This is an UNofficial SDK and CLI for Vectara's RAG platform. Use at your own risk. Vectara does NOT provide support for this SDK or CLI.

Metadata

Release files for vektara 0.0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for vektara 0.0.6
File Size Uploaded Provenance
vektara-0.0.6.tar.gz 57.9 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for vektara 0.0.6
File Interpreter ABI Platform
vektara-0.0.6-py3-none-any.whl Python 3 none any Details

Total release size: 101.8 kB

Release files / vektara-0.0.6.tar.gz

Download URL vektara-0.0.6.tar.gz
Size 57.9 kB
Tags Source
SHA-256 checksum
How to use checksums
d1e830580b8678bc1c6f862eff193e1163d437f7c6f9e02b71fc4b9a5ff906df
BLAKE2b-256 checksum
How to use checksums
720740efdee01f96b0f5c4d95f4e9ff18de2f6a862c3a0891991f5e69f179c2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/6.11.0 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.31.0 rfc3986/1.5.0 tqdm/4.66.1 urllib3/1.26.5 CPython/3.10.12

Release files / vektara-0.0.6-py3-none-any.whl

Download URL vektara-0.0.6-py3-none-any.whl
Size 43.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e2c1b5235727e760bd420945921607c5f3973285b92363c98bc8417035acc612
BLAKE2b-256 checksum
How to use checksums
c9f884595f3ac514ca076390fd7a1334675ecd8884fdbb635bf4c3daa566d186
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 colorama/0.4.4 importlib-metadata/6.11.0 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.31.0 rfc3986/1.5.0 tqdm/4.66.1 urllib3/1.26.5 CPython/3.10.12

Security for vektara 0.0.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page