Skip to content

Commit cbe650c

Browse files
committed
LlamaIndex: Implement suggestions by CodeRabbit
1 parent 8200337 commit cbe650c

File tree

4 files changed

+33
-33
lines changed

4 files changed

+33
-33
lines changed

docs/integrate/llamaindex/index.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@
1616
:::{rubric} About
1717
:::
1818

19-
[LlamaIndex] is a data framework for Large Language Models (LLMs). It comes with
20-
pre-trained models on massive public datasets such as GPT-4 or Llama 2, and
21-
provides an interface to external data sources allowing for natural language
22-
querying on your private data.
19+
[LlamaIndex] is a data framework for Large Language Models (LLMs). It integrates
20+
with providers and models such as GPT‑4 or Llama 3/4, and provides interfaces to
21+
external data sources for natural‑language querying of your private data.
2322

24-
Azure Open AI Service is a fully managed service that runs on the Azure global
23+
Azure OpenAI Service is a fully managed service that runs on the Azure global
2524
infrastructure and allows developers to integrate OpenAI models into their
26-
applications. Through Azure Open AI API one can easily access a wide range of
25+
applications. Through the Azure OpenAI API, you can access a wide range of
2726
AI models in a scalable and reliable way.
2827

2928
:::{rubric} Use case examples
@@ -55,8 +54,8 @@ contemporary large language models, optionally offline.
5554
:::{grid-item-card} Demo: Using LlamaIndex with OpenAI and CrateDB
5655
:link: llamaindex-tutorial
5756
:link-type: ref
58-
- Connect your CrateDB data to an LLM using OpenAI or Azure OpenAI.
59-
- Text-to-SQL / Talk to your data: Query the database in human language; query CrateDB in plain English.
57+
- Connect CrateDB to an LLM via OpenAI or Azure OpenAI.
58+
- Text‑to‑SQL: Query CrateDB in natural language.
6059

6160
{tags-primary}`Cloud LLM`
6261
{tags-secondary}`LLM`

docs/integrate/llamaindex/synopsis.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ contemporary large language models, optionally offline.
99
## Install
1010
Project dependencies. For example, use them in a `requirements.txt` file.
1111
```shell
12-
langchain-openai<0.3
13-
llama-index-embeddings-langchain<0.4
14-
llama-index-embeddings-openai<0.4
15-
llama-index-llms-azure-openai<0.4
16-
llama-index-llms-openai<0.4
12+
langchain-openai<0.4
13+
llama-index-embeddings-langchain<0.5
14+
llama-index-embeddings-openai<0.6
15+
llama-index-llms-azure-openai<0.5
16+
llama-index-llms-ollama<0.8
17+
llama-index-llms-openai<0.6
1718
sqlalchemy-cratedb
1819
```
1920

@@ -33,14 +34,14 @@ import os
3334
from llama_index.llms.ollama import Ollama
3435
from llama_index.llms.openai import OpenAI
3536
from llama_index.core import SQLDatabase
36-
from llama_index.core.indices.struct_store import NLSQLTableQueryEngine
37+
from llama_index.core.query_engine import NLSQLTableQueryEngine
3738
import sqlalchemy as sa
3839
```
3940
:::
4041

4142
:::{grid-item}
4243
:columns: 4
43-
Provision LLM using OpenAI model.
44+
Provision an LLM using an OpenAI model.
4445
:::
4546
:::{grid-item}
4647
:columns: 8
@@ -55,14 +56,14 @@ llm = OpenAI(
5556

5657
:::{grid-item}
5758
:columns: 4
58-
Alternatively, provision LLM using self-hosted model.
59+
Alternatively, provision an LLM using a self-hosted model.
5960
:::
6061
:::{grid-item}
6162
:columns: 8
6263
```python
6364
llm = Ollama(
6465
base_url=os.getenv("OLLAMA_BASE_URL", "http://localhost:11434"),
65-
model="gemma3:1b",
66+
model=os.getenv("OLLAMA_MODEL", "gemma3:1b"),
6667
temperature=0.0,
6768
request_timeout=120.0,
6869
keep_alive=-1,
@@ -78,7 +79,6 @@ Connect to CrateDB.
7879
:columns: 8
7980
```python
8081
database = sa.create_engine(os.getenv("CRATEDB_SQLALCHEMY_URL", "crate://crate@localhost:4200"))
81-
database.connect()
8282
```
8383
:::
8484

@@ -117,7 +117,7 @@ answer = nlsql.query("Quelle est la valeur moyenne pour le capteur 1 ?")
117117
import os
118118
import sqlalchemy as sa
119119

120-
from llama_index.core.utilities.sql_wrapper import SQLDatabase
120+
from llama_index.core import SQLDatabase
121121
from llama_index.core.query_engine import NLSQLTableQueryEngine
122122
from llama_index.core import Settings
123123

docs/integrate/llamaindex/tutorial.md

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@
33

44
## Introduction
55

6-
[LlamaIndex](https://www.llamaindex.ai/) is a data framework for Large Language Models (LLMs). It comes with pre-trained models on massive public datasets such as [GPT-4](https://openai.com/index/gpt-4/) or [Llama 4](https://www.llama.com/models/llama-4/) and provides an interface to external data sources allowing for natural language querying on your private data.
6+
[LlamaIndex](https://www.llamaindex.ai/) is a data framework for Large Language Models (LLMs).
7+
It integrates with models such as [GPT‑4](https://openai.com/index/gpt-4/) or [Llama 4](https://www.llama.com/models/llama-4/) and provides interfaces to external data sources for natural‑language querying of your private data.
78

8-
[Azure Open AI Service](https://azure.microsoft.com/en-us/products/ai-services/openai-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.
9+
[Azure OpenAI Service](https://azure.microsoft.com/en-us/products/ai-services/openai-service) is a fully managed service on the Azure global infrastructure that lets developers integrate OpenAI models into applications. Through the Azure OpenAI API, you can access a wide range of AI models in a scalable and reliable way.
910

10-
In this tutorial, we will illustrate how to augment existing LLMs with data stored in CrateDB through the LlamaIndex framework and Azure Open AI Service. By doing this, you will be able to use the power of generative AI models with your own data in just a few lines of code.
11+
This tutorial shows how to augment LLMs with data stored in CrateDB using LlamaIndex and Azure OpenAI, enabling natural‑language queries over your data.
1112

1213
If you want to run this in your own environment, we've provided all of the code and supporting resources that you'll need in the [`cratedb-examples`](https://github.com/crate/cratedb-examples/tree/main/topic/machine-learning/llama-index) GitHub repository.
1314

1415
## Prerequisites
1516

1617
* Python 3.10 or higher
1718
* Recent version of LlamaIndex, please follow the [installation instructions](https://gpt-index.readthedocs.io/en/latest/getting_started/installation.html)
19+
* `sqlalchemy-cratedb`
20+
* `SQLAlchemy` (if not pulled transitively)
1821
* Running instance of [CrateDB](https://console.cratedb.cloud/)
19-
* [An Azure subscription](https://azure.microsoft.com/en-gb/free/cognitive-services/) and [Azure OpenAI resource](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal) in your desired subscription
22+
* [Azure subscription](https://azure.microsoft.com/en-gb/free/cognitive-services/) and [Azure OpenAI resource](https://learn.microsoft.com/en-us/azure/ai-services/openai/how-to/create-resource?pivots=web-portal)
2023

2124
## Deploy models in Azure OpenAI
2225

@@ -28,9 +31,9 @@ To deploy the models required for this tutorial, follow these steps:
2831

2932
![92c692f4-2cc8-4661-9fc3-7c037cccbd28|690x263](https://us1.discourse-cdn.com/flex020/uploads/crate/original/2X/e/e0a411357b62eb67995b818b4e235d8c64aebc99.png)
3033

31-
2. This will open Azure AI Studio. Azure AI Studio enables developers to build, run, and deploy AI applications. Click on the *Create new deployment* button to deploy the following models:
32-
1. **GPT-35-turbo** for text generation tasks
33-
2. **text-embedding-ada-002** for generating embeddings
34+
2. This opens Azure AI Studio. Click *Create new deployment* and deploy:
35+
1. A chat/completions model (e.g., **gpt-4o-mini**)
36+
2. An embeddings model (e.g., **text-embedding-3-large**)
3437

3538
The basic deployment of each model is straightforward in Azure OpenAI Studio: You need to select the model you want to deploy and specify the unique name:
3639

@@ -136,7 +139,6 @@ We use sqlalchemy, a popular SQL database toolkit, to connect to CrateDB and SQL
136139

137140
```python
138141
engine_crate = sa.create_engine(os.getenv("CRATEDB_SQLALCHEMY_URL"))
139-
engine_crate.connect()
140142
```
141143
The value of `CRATEDB_SQLALCHEMY_URL` should be a URL format connection string containing the hostname, username and password for your CrateDB instance:
142144

@@ -153,8 +155,7 @@ sql_database = SQLDatabase(
153155
)
154156
```
155157

156-
Then use that to create am instance of `NLSQLTableQueryEngine`:
157-
158+
Then create an instance of `NLSQLTableQueryEngine`:
158159
```python
159160
query_engine = NLSQLTableQueryEngine(
160161
sql_database=sql_database,
@@ -183,15 +184,15 @@ print("Answer was:", answer)
183184
Often, we are also interested in the query that produces the output. This is included in the answer's metadata:
184185

185186
```python
186-
print(answer.metadata))
187+
print(answer.metadata)
187188
# {'result': [(17.033333333333335,)], 'sql_query': 'SELECT AVG(value) FROM time_series_data WHERE sensor_id = 1'}
188189
```
189190

190191
## Takeaway
191192

192193
In this tutorial, we've embarked on the journey of using a natural language interface to query CrateDB data. We've explored how to seamlessly connect your data to the power of LLM using LlamaIndex and the capabilities of Azure OpenAI.
193194

194-
This tutorial is just the beginning. You can expect further resources, documentation, and tutorials related to CrateDB and generative AI from us. Also, stay tuned for the CrateDB 5.5 release: we will soon announce the support for the vector store and search, allowing you to implement similarity-based data retrieval efficiently.
195+
This tutorial is a starting point. Explore additional resources on CrateDB and generative AI as they become available.
195196

196197
If you want to try this out yourself, you can find the full example code and supporting resources in the [`cratedb-examples` GitHub repository](https://github.com/crate/cratedb-examples/tree/main/topic/machine-learning/llama-index).
197198

docs/start/query/ai-integration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,8 +212,8 @@ frameworks and libraries, see CrateDB's support for MLflow and PyCaret at
212212

213213

214214
## Text-to-SQL
215-
Text-to-SQL: Talk to your data using human language and contemporary large
216-
language models, optionally offline.
215+
Text‑to‑SQL lets you query data in natural language with contemporary
216+
large language models, optionally offline.
217217
:::{seealso}
218218
{ref}`llamaindex-synopsis`
219219
:::

0 commit comments

Comments
 (0)