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.6.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.6.0
File Size Uploaded Provenance Actions
llama_index_selectors_notdiamond-0.6.0.tar.gz 5.8 kB Without provenance Details for llama_index_selectors_notdiamond-0.6.0.tar.gz

Built distribution (wheel)

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

Total release size: 11.1 kB

Release files / llama_index_selectors_notdiamond-0.6.0.tar.gz

Download URL llama_index_selectors_notdiamond-0.6.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
749680fb2cd95e0fe1d2dbd8426386d26fa0773c9c427e055e9ef2789bdc54de
BLAKE2b-256 checksum
How to use checksums
06999cea207fa9a92c07160c4ef28edba644345720fbc1e255f90708264ecb64
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.6.0-py3-none-any.whl

Download URL llama_index_selectors_notdiamond-0.6.0-py3-none-any.whl
Size 5.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
fc18d3bcc88a506787e875fd78cdddbe4d1c35d4c7e55733f123088b82bed47b
BLAKE2b-256 checksum
How to use checksums
d56a415b59b31e02bd884a167e1397062730fa677a9427b26ff391587bfd6d90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.6.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