Skip to main content

✨🦙 Argilla's LlamaIndex Integration

Argilla integration into the LlamaIndex workflow

[!TIP] To discuss, get support, or give feedback join Discord in #argilla-distilabel-general and #argilla-distilabel-help. You will be able to engage with our amazing community and the core developers of argilla and distilabel.

This integration allows the user to include the feedback loop that Argilla offers into the LlamaIndex ecosystem. It's based on a callback handler to be run within the LlamaIndex workflow.

Don't hesitate to check out both LlamaIndex and Argilla

Getting Started

You first need to install argilla-llama-index as follows:

pip install argilla-llama-index

If you already have deployed Argilla, you can skip this step. Otherwise, you can quickly deploy Argilla following this guide.

Basic Usage

To easily log your data into Argilla within your LlamaIndex workflow, you only need to initialize the handler and attach it to the LlamaIndex dispatcher. This ensured that the predictions obtained using LlamaIndex are automatically logged to the Argilla instance.

  • dataset_name: The name of the dataset. If the dataset does not exist, it will be created with the specified name. Otherwise, it will be updated.
  • api_url: The URL to connect to the Argilla instance.
  • api_key: The API key to authenticate with the Argilla instance.
  • number_of_retrievals: The number of retrieved documents to be logged. Defaults to 0.
  • workspace_name: The name of the workspace to log the data. By default, the first available workspace.

For more information about the credentials, check the documentation for users and workspaces.

from llama_index.core.instrumentation import get_dispatcher
from argilla_llama_index import ArgillaHandler

argilla_handler = ArgillaHandler(
    dataset_name="query_llama_index",
    api_url="http://localhost:6900",
    api_key="argilla.apikey",
    number_of_retrievals=2,
)
root_dispatcher = get_dispatcher()
root_dispatcher.add_span_handler(argilla_handler)
root_dispatcher.add_event_handler(argilla_handler)

Let's log some data into Argilla. With the code below, you can create a basic LlamaIndex workflow. We will use GPT3.5 from OpenAI as our LLM (OpenAI API key). Moreover, we will use an example .txt file obtained from the LlamaIndex documentation.

import os

from llama_index.core import Settings, VectorStoreIndex, SimpleDirectoryReader
from llama_index.llms.openai import OpenAI

# LLM settings
Settings.llm = OpenAI(
  model="gpt-3.5-turbo", temperature=0.8, openai_api_key=os.getenv("OPENAI_API_KEY")
)

# Load the data and create the index
documents = SimpleDirectoryReader("data").load_data()
index = VectorStoreIndex.from_documents(documents)

# Create the query engine with the same similarity top k as the number of retrievals
query_engine = index.as_query_engine(similarity_top_k=2)

Now, let's run the query_engine to have a response from the model. The generated response will be logged into Argilla.

response = query_engine.query("What did the author do growing up?")
response

Argilla UI

Metadata

Release files for argilla-llama-index 2.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for argilla-llama-index 2.1.0
File Size Uploaded
argilla_llama_index-2.1.0.tar.gz 1.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for argilla-llama-index 2.1.0
File Interpreter ABI Platform
argilla_llama_index-2.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 1.2 MB

Release files / argilla_llama_index-2.1.0.tar.gz

Download URL argilla_llama_index-2.1.0.tar.gz
Size 1.1 MB
Tags Source
SHA-256 checksum
How to use checksums
141fcf8b9c6d4e0b945320e4ad4bc32b4c4705ff15e6b0f3492049f4201b78bd
BLAKE2b-256 checksum
How to use checksums
0ed92251be287f6e27831d0c5ab71405f79a17a28dadc4032a178fcb86462b09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / argilla_llama_index-2.1.0-py3-none-any.whl

Download URL argilla_llama_index-2.1.0-py3-none-any.whl
Size 16.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8da2966eaec679e9252289122fdd43ac04f0355aa8d0f4fe8834193726a45d42
BLAKE2b-256 checksum
How to use checksums
5d70c590d1770f19f5fead8a57165cbe56a47126a5a327413a978d9f932ff2dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release history Release notifications | RSS feed

This release

2.1.0 This release

2 release files

2.0.0

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page