Retrieval
GenAIScript provides various utilities to retrieve content and augment the prompt. This technique is typically referred to as RAG (Retrieval-Augmentation-Generation) in the literature.
Vector Search
GenAIScript provides various vector database to support embeddings search and retrieval augmented generation (RAG).
The retrieve.index
creates or loads an existing index.
// index creationconst index = await retrieval.index("animals")// indexingawait index.insertOrUpdate(env.files)// searchconst res = await index.search("cat dog")def("RAG", res)
Local Index
By default, vector are stored locally in files under the .genaiscript
folder using a local vector database based on vectra. The embeddings are computed
using the embeddings
model alias (it can also be configured through the options).
const index = await retrieval.index("animals", { embeddingsModel: "ollama:nomic-embed-text",})
The index is serialized by default. If you wish to reset it on every execution, set deleteIfExists: true
.
Azure AI Search
GenAIScript also supports using an Azure AI Search service. The Azure AI Search uses the simple query syntax.
const index = retrieval.index("animals", { type: "azure_ai_search" })
To configure the service, you will need to set the AZURE_AI_SEARCH_ENDPOINT
and AZURE_AI_SEARCH_API_KEY
environment variables in your .env
file.
Please refer to the Authentication documentation for more details.
AZURE_AI_SEARCH_ENDPOINT=https://{{service-name}}.search.windows.net/AZURE_AI_SEARCH_API_KEY=...
Further index management can be done through the Azure Portal.
Fuzz Search
The retrieve.fuzzSearch
performs a “traditional” fuzzy search to find the most similar documents to the prompt.
const files = await retrieval.fuzzSearch("cat dog", env.files)
Web Search
The retrieval.webSearch
performs a web search using a search engine API. You will need to provide API keys for the search engine you want to use.
const { webPages } = await retrieval.webSearch("cat dog")def("RAG", webPages)
Bing
To enable Bing search, configure the BING_SEARCH_API_KEY
secret in your .env
file. Learn more about configuring the Bing Search API.