Open In Colab


This notebook shows how you can use Predibase-hosted LLM’s within Llamaindex. You can add Predibase to your existing Llamaindex worklow to:

  1. Deploy and query pre-trained or custom open source LLM’s without the hassle

  2. Operationalize an end-to-end Retrieval Augmented Generation (RAG) system

  3. Fine-tune your own LLM in just a few lines of code

Getting Started#

  1. Sign up for a free Predibase account here

  2. Create an Account

  3. Go to Settings > My profile and Generate a new API Token.

%pip install llama-index-llms-predibase
!pip install llama-index --quiet
!pip install predibase --quiet
!pip install sentence-transformers --quiet
import os

from llama_index.llms.predibase import PredibaseLLM

Flow 1: Query Predibase LLM directly#

llm = PredibaseLLM(
    model_name="llama-2-13b", temperature=0.3, max_new_tokens=512
# You can query any HuggingFace or fine-tuned LLM that's hosted on Predibase
result = llm.complete("Can you recommend me a nice dry white wine?")

Flow 2: Retrieval Augmented Generation (RAG) with Predibase LLM#

from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
from llama_index.core.embeddings import resolve_embed_model
from llama_index.core.node_parser import SentenceSplitter

Download Data#

!mkdir -p 'data/paul_graham/'
!wget '' -O 'data/paul_graham/paul_graham_essay.txt'

Load Documents#

documents = SimpleDirectoryReader("./data/paul_graham/").load_data()

Configure Predibase LLM#

llm = PredibaseLLM(
embed_model = resolve_embed_model("local:BAAI/bge-small-en-v1.5")
splitter = SentenceSplitter(chunk_size=1024)

Setup and Query Index#

index = VectorStoreIndex.from_documents(
    documents, transformations=[splitter], embed_model=embed_model
query_engine = index.as_query_engine(llm=llm)
response = query_engine.query("What did the author do growing up?")