LlamaIndex

About

LlamaIndex is a data framework for Large Language Models (LLMs). It comes with pre-trained models on massive public datasets such as GPT-4 or Llama 2, and provides an interface to external data sources allowing for natural language querying on your private data.

Azure Open AI Service is a fully managed service that runs on the Azure global infrastructure and allows developers to integrate OpenAI models into their applications. Through Azure Open AI API one can easily access a wide range of AI models in a scalable and reliable way.

Use case examples

What can you do with LlamaIndex?

Install

Project dependencies. For example, use them in a requirements.txt file.

langchain-openai<0.3
llama-index-embeddings-langchain<0.4
llama-index-embeddings-openai<0.4
llama-index-llms-azure-openai<0.4
llama-index-llms-openai<0.4
sqlalchemy-cratedb

Synopsis

Code example using the LlamaIndex package
import os
import sqlalchemy as sa

from llama_index.core.utilities.sql_wrapper import SQLDatabase
from llama_index.core.query_engine import NLSQLTableQueryEngine
from llama_index.core import Settings

engine = sa.create_engine("crate://localhost:4200/")
engine.connect()

sql_database = SQLDatabase(
    engine, 
    include_tables=["testdrive"]
)

query_engine = NLSQLTableQueryEngine(
    sql_database=sql_database,
    tables=[os.getenv("CRATEDB_TABLE_NAME")],
    llm=Settings.llm
)

query_str = "What is the average value for sensor 1?"
answer = query_engine.query(query_str)
print(answer.get_formatted_sources())
print("Query was:", query_str)
print("Answer was:", answer)

# query was: What is the average value for sensor 1?
# answer was: The average value for sensor 1 is 17.03.

Learn

Tutorials

Demo: Using LlamaIndex with OpenAI and CrateDB

  • Connect your CrateDB data to an LLM using OpenAI or Azure OpenAI.

  • Query the database in human language, i.e. query CrateDB in plain English.

Tutorial README Program on GitHub

Fundamentals
LLM
NLP
RAG