.ipynb
.pdf
Vectara
 Contents 
Connecting to Vectara from LangChain
Similarity search
Similarity search with score
Vectara as a Retriever
Vectara#
Vectara is a API platform for building LLM-powered applications. It provides a simple to use API for document indexing and query that is managed by Vectara and is optimized for performance and accuracy.
This notebook shows how to use functionality related to the Vectara vector database.
See the Vectara API documentation  for more information on how to use the API.
We want to use OpenAIEmbeddings so we have to get the OpenAI API Key.
import os
import getpass
os.environ['OPENAI_API_KEY'] = getpass.getpass('OpenAI API Key:')
OpenAI API Key:········
from langchain.embeddings.openai import OpenAIEmbeddings
from langchain.text_splitter import CharacterTextSplitter
from langchain.vectorstores import Vectara
from langchain.document_loaders import TextLoader
loader = TextLoader('../../../state_of_the_union.txt')
documents = loader.load()
text_splitter = CharacterTextSplitter(chunk_size=1000, chunk_overlap=0)
docs = text_splitter.split_documents(documents)
embeddings = OpenAIEmbeddings()
Connecting to Vectara from LangChain#
The Vectara API provides simple API endpoints for indexing and querying.
vectara = Vectara.from_documents(docs, embedding=None)
Similarity search#
The simplest scenario for using Vectara is to perform a similarity search.
query = "What did the president say about Ketanji Brown Jackson"
found_docs = vectara.similarity_search(query, n_sentence_context=0)
print(found_docs[0].page_content)
rtdocs_stable/api.python.langchain.com/en/stable/modules/indexes/vectorstores/examples/vectara.html