Sample code for the article on LlamaIndex#718
Conversation
martin-martin
left a comment
There was a problem hiding this comment.
Tried it out, thanks for the updates, all is working for me (except I'm still timing out with Ollama ¯_(ツ)_/¯). Also asking Copilot for a review, but IMO we're good to go.
There was a problem hiding this comment.
Pull request overview
This PR adds sample code for a Real Python tutorial on LlamaIndex, a framework for building RAG (Retrieval-Augmented Generation) applications. The code demonstrates various ways to use LlamaIndex with different LLM providers (OpenAI, Google, Ollama) and indexing strategies.
Key Changes
- Sample Python scripts demonstrating LlamaIndex usage with synchronous and asynchronous queries
- Examples showing different index types (Vector, Summary, Tree)
- Integration examples with multiple LLM providers (OpenAI, Google Gemini, Ollama)
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| python-llamaindex/single_query.py | Basic example showing single query execution with index persistence |
| python-llamaindex/async_query.py | Demonstrates asynchronous query execution for multiple queries |
| python-llamaindex/indices.py | Compares different index types (Vector, Summary, Tree) |
| python-llamaindex/documents.py | Simple document loading example |
| python-llamaindex/demo.py | Minimal demo showing basic LlamaIndex workflow |
| python-llamaindex/demo_ollama.py | Integration example with Ollama local LLM |
| python-llamaindex/demo_gpt5.py | OpenAI integration example (contains nonexistent model) |
| python-llamaindex/demo_google.py | Google Gemini integration example (contains nonexistent model) |
| python-llamaindex/requirements.txt | Python dependencies for all examples |
| python-llamaindex/README.md | Brief documentation linking to the tutorial |
| python-llamaindex/data/pep8.rst | Sample data file (PEP 8 style guide) for indexing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| DATA_FILE = BASE_DIR / "data" / "pep8.rst" | ||
|
|
||
|
|
||
| def get_index(persist_dir=PERSIST_DIR, data_file=DATA_FILE): |
There was a problem hiding this comment.
The function get_index lacks a docstring. Consider adding documentation that explains its purpose, parameters, and return value. For example:
def get_index(persist_dir=PERSIST_DIR, data_file=DATA_FILE):
"""Load or create a VectorStoreIndex.
Args:
persist_dir: Directory where the index is persisted. Defaults to PERSIST_DIR.
data_file: Path to the data file to index. Defaults to DATA_FILE.
Returns:
VectorStoreIndex: The loaded or newly created index.
"""| def get_index(persist_dir=PERSIST_DIR, data_file=DATA_FILE): | |
| def get_index(persist_dir=PERSIST_DIR, data_file=DATA_FILE): | |
| """Load or create a VectorStoreIndex. | |
| Args: | |
| persist_dir: Directory where the index is persisted. Defaults to PERSIST_DIR. | |
| data_file: Path to the data file to index. Defaults to DATA_FILE. | |
| Returns: | |
| VectorStoreIndex: The loaded or newly created index. | |
| """ |
| DATA_FILE = BASE_DIR / "data" / "pep8.rst" | ||
|
|
||
|
|
||
| def get_index(persist_dir=PERSIST_DIR, data_file=DATA_FILE): |
There was a problem hiding this comment.
The function get_index lacks a docstring. Consider adding documentation that explains its purpose, parameters, and return value. For example:
def get_index(persist_dir=PERSIST_DIR, data_file=DATA_FILE):
"""Load or create a VectorStoreIndex.
Args:
persist_dir: Directory where the index is persisted. Defaults to PERSIST_DIR.
data_file: Path to the data file to index. Defaults to DATA_FILE.
Returns:
VectorStoreIndex: The loaded or newly created index.
"""| def get_index(persist_dir=PERSIST_DIR, data_file=DATA_FILE): | |
| def get_index(persist_dir=PERSIST_DIR, data_file=DATA_FILE): | |
| """ | |
| Load or create a VectorStoreIndex. | |
| Args: | |
| persist_dir (Path): Directory where the index is persisted. Defaults to PERSIST_DIR. | |
| data_file (Path): Path to the data file to index. Defaults to DATA_FILE. | |
| Returns: | |
| VectorStoreIndex: The loaded or newly created index. | |
| """ |
Where to put new files:
my-awesome-articleHow to merge your changes: