Skip to main content

LlamaIndex Selectors Integration: NotDiamond

Not Diamond offers an AI-powered model router that automatically determines which LLM is best suited to respond to any query, improving LLM output quality by combining multiple LLMs into a meta-model that learns when to call each LLM.

Not Diamond supports cost and latency tradeoffs, customized router training, and real-time router personalization. Learn more via the documentation.

Installation

pip install llama-index-selectors-notdiamond

Configuration

  • API keys: You need API keys from Not Diamond and any LLM you want to use.

Quick Start

import os
from typing import List

from llama_index.core import (
    SimpleDirectoryReader,
    VectorStoreIndex,
    SummaryIndex,
    Settings,
)
from llama_index.core.query_engine import RouterQueryEngine
from llama_index.core.tools import QueryEngineTool
from llama_index.selectors.notdiamond.base import NotDiamondSelector

from notdiamond import NotDiamond


# Set up your API keys
os.environ["OPENAI_API_KEY"] = "sk-..."
os.environ["ANTHROPIC_API_KEY"] = "sk-ant-..."
os.environ["NOTDIAMOND_API_KEY"] = "sk-..."


# Create indexes
documents = SimpleDirectoryReader("data/paul_graham").load_data()
nodes = Settings.node_parser.get_nodes_from_documents(documents)

vector_index = VectorStoreIndex.from_documents(documents)
summary_index = SummaryIndex.from_documents(documents)
query_text = "What was Paul Graham's role at Yahoo?"


# Set up Tools for the QueryEngine
list_query_engine = summary_index.as_query_engine(
    response_mode="tree_summarize",
    use_async=True,
)
vector_query_engine = vector_index.as_query_engine()

list_tool = QueryEngineTool.from_defaults(
    query_engine=list_query_engine,
    description=(
        "Useful for summarization questions related to Paul Graham eassy on"
        " What I Worked On."
    ),
)

vector_tool = QueryEngineTool.from_defaults(
    query_engine=vector_query_engine,
    description=(
        "Useful for retrieving specific context from Paul Graham essay on What"
        " I Worked On."
    ),
)


# Create a NotDiamondSelector and RouterQueryEngine
client = NotDiamond(
    api_key=os.environ["NOTDIAMOND_API_KEY"],
    llm_configs=["openai/gpt-4o", "anthropic/claude-3-5-sonnet-20240620"],
)
preference_id = client.create_preference_id()
client.preference_id = preference_id

nd_selector = NotDiamondSelector(client=client)

query_engine = RouterQueryEngine(
    selector=nd_selector,
    query_engine_tools=[
        list_tool,
        vector_tool,
    ],
)


# Use Not Diamond to Query Indexes
response = query_engine.query(
    "Please summarize Paul Graham's working experience."
)
print(str(response))

Metadata

Release files for llama-index-selectors-notdiamond 0.5.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 llama-index-selectors-notdiamond 0.5.0
File Size Uploaded Provenance Actions
llama_index_selectors_notdiamond-0.5.0.tar.gz 5.8 kB Without provenance Details for llama_index_selectors_notdiamond-0.5.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for llama-index-selectors-notdiamond 0.5.0
File Interpreter ABI Platform Actions
llama_index_selectors_notdiamond-0.5.0-py3-none-any.whl Python 3 none any Details for llama_index_selectors_notdiamond-0.5.0-py3-none-any.whl

Total release size: 11.1 kB

Release files / llama_index_selectors_notdiamond-0.5.0.tar.gz

Download URL llama_index_selectors_notdiamond-0.5.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cfcace922fa5dcc8aa71985dddfe50a612d1be4013c541546ce90df9737bd131
BLAKE2b-256 checksum
How to use checksums
8342cb56a3a917a74832170d340caf5a901143f2daceb3166c20a26485a9acff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / llama_index_selectors_notdiamond-0.5.0-py3-none-any.whl

Download URL llama_index_selectors_notdiamond-0.5.0-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c107f0dae36ec3ea14789823d544481210c3cc3b6d97414ded77f0aee2c6d955
BLAKE2b-256 checksum
How to use checksums
1a367f3d8491883df50bfac8304cad978bdf0d759182e8b31eb47c2f730a8605
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for llama-index-selectors-notdiamond 0.5.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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