OpenInference LlamaIndex Instrumentation
Project description
OpenInference LlamaIndex Instrumentation
Python auto-instrumentation library for LlamaIndex.
These traces are fully OpenTelemetry compatible and can be sent to an OpenTelemetry collector for viewing, such as arize-phoenix
.
Installation
pip install openinference-instrumentation-llama-index
Compatibility
llama-index version | openinference-instrumentation-llama-index version |
---|---|
>=0.10.0 | >=1.0.0 |
<0.10.0, >=0.9.14 | 0.1.3 |
Quickstart
Install packages needed for this demonstration.
pip install openinference-instrumentation-llama-index llama-index arize-phoenix opentelemetry-sdk opentelemetry-exporter-otlp
Start the Phoenix app in the background as a collector. By default, it listens on http://localhost:6006
. You can visit the app via a browser at the same address.
The Phoenix app does not send data over the internet. It only operates locally on your machine.
python -m phoenix.server.main serve
The following Python code sets up the LlamaIndexInstrumentor
to trace llama-index
and send the traces to Phoenix at the endpoint shown below.
from openinference.instrumentation.llama_index import LlamaIndexInstrumentor
from opentelemetry import trace as trace_api
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter
from opentelemetry.sdk import trace as trace_sdk
from opentelemetry.sdk.trace.export import SimpleSpanProcessor
endpoint = "http://127.0.0.1:6006/v1/traces"
tracer_provider = trace_sdk.TracerProvider()
trace_api.set_tracer_provider(tracer_provider)
tracer_provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(endpoint)))
LlamaIndexInstrumentor().instrument()
To demonstrate tracing, we'll use LlamaIndex below to query a document.
First, download a text file.
import tempfile
from urllib.request import urlretrieve
from llama_index.core import SimpleDirectoryReader
url = "https://raw.githubusercontent.com/Arize-ai/phoenix-assets/main/data/paul_graham/paul_graham_essay.txt"
with tempfile.NamedTemporaryFile() as tf:
urlretrieve(url, tf.name)
documents = SimpleDirectoryReader(input_files=[tf.name]).load_data()
Next, we'll query using OpenAI. To do that you need to set up your OpenAI API key in an environment variable.
import os
os.environ["OPENAI_API_KEY"] = "<your openai key>"
Now we can query the indexed documents.
from llama_index.core import VectorStoreIndex
query_engine = VectorStoreIndex.from_documents(documents).as_query_engine()
print(query_engine.query("What did the author do growing up?"))
Visit the Phoenix app at http://localhost:6006
to see the traces.
More Info
More details about tracing with OpenInference and Phoenix can be found in the Phoenix documentation.
For AI/ML observability solutions in production, including a cloud-based trace collector, visit Arize.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for openinference_instrumentation_llama_index-1.2.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c4d60e3589b86e7ea9bb0151fbc871e5732e5aabc84d11451b8cb8543c2a882 |
|
MD5 | d1d88b5da6de144db97349f4ddbbe2cf |
|
BLAKE2b-256 | a6eaf210ff2af9cb22356e17b92e365e5da7a08b86e1d8c9415845b30562664d |
Hashes for openinference_instrumentation_llama_index-1.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ddda64d8d3f0521d3aa1e02e0887b15e0a1bee5a44915f3c17c53175a115586f |
|
MD5 | 8e7792f1653c1d090b5a3cec4db4c308 |
|
BLAKE2b-256 | 2d9299c8a283d62ca2654aeb9c7612f7d0a297282b15db40b2c1720239249fb9 |