Skip to main content

RagDict

RagDict is an enhanced Python dictionary with fuzzy key matching support using RAG (Retrieval-Augmented Generation) and LLM.

Features

  • Works like a regular Python dictionary for exact key matches
  • Automatically finds similar keys when an exact match is not found
  • Uses OpenAI embeddings to find semantically similar keys
  • Applies LLM to select the most appropriate key from candidates
  • Fully customizable similarity parameters and models

Installation

pip install ragdict

Or using uv:

uv pip install ragdict

Usage

Basic Example

from ragdict import RagDict
import os

# Set your OpenAI API key
os.environ["OPENAI_API_KEY"] = "your-api-key"

# Create a dictionary with car prices
car_prices = RagDict({
    "Toyota Camry": 25000,
    "Honda Accord": 27000,
    "Tesla Model 3": 40000,
    "Ford Mustang": 35000,
    "Chevrolet Corvette": 60000
})

# Exact match works like a normal dictionary
price = car_prices["Toyota Camry"]  # 25000

# Fuzzy matching when the key is not exact
price = car_prices["Toyot Camri"]  # Will find "Toyota Camry" and return 25000
price = car_prices["Tesla Model Three"]  # Will find "Tesla Model 3" and return 40000
price = car_prices["Chevy Corvette"]  # Will find "Chevrolet Corvette" and return 60000

Parameter Customization

# Creating a dictionary with customizable parameters
products = RagDict(
    {
        "iPhone 14 Pro": 999,
        "Samsung Galaxy S23": 799,
        "Google Pixel 7": 599
    },
    embedding_model="text-embedding-3-large",  # Embedding model
    llm_model="gpt-4o",  # LLM model for key selection
    similarity_threshold=0.6,  # Minimum similarity threshold (0-1)
    top_k=5,  # Number of top candidates to consider
    api_key="your-openai-api-key"  # You can pass the API key directly
)

# Fuzzy search
price = products["iPhone 14"]  # Will find "iPhone 14 Pro"
price = products["Samsung S23"]  # Will find "Samsung Galaxy S23"

How It Works

  1. When you request a key, RagDict first tries to find an exact match
  2. If an exact match is not found, RagDict:
    • Creates an embedding for the requested key
    • Finds semantically similar keys based on cosine similarity
    • Filters keys below the similarity threshold
    • Uses LLM to select the most appropriate key from candidates
    • Returns the value associated with the selected key

Requirements

  • Python 3.8+
  • OpenAI API key
  • Packages: openai, numpy

License

MIT

Metadata

Release files for ragdict 0.2.1

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

Source distribution (sdist)

Source distribution for ragdict 0.2.1
File Size Uploaded Provenance Actions
ragdict-0.2.1.tar.gz 6.4 kB Without provenance Details for ragdict-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for ragdict 0.2.1
File Interpreter ABI Platform Actions
ragdict-0.2.1-py3-none-any.whl Python 3 none any Details for ragdict-0.2.1-py3-none-any.whl

Total release size: 12.4 kB

Release files / ragdict-0.2.1.tar.gz

Download URL ragdict-0.2.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
670fe406630f641c1f73f161b9efd340d38771e161da048dce28b356ca6f8619
BLAKE2b-256 checksum
How to use checksums
a2c3c89abce7ab4a5b9dba5d8d53e8812811c4afbf43c9d9741324dc153c13be
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Release files / ragdict-0.2.1-py3-none-any.whl

Download URL ragdict-0.2.1-py3-none-any.whl
Size 6.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a2d09930d871398ee4478d22d1f3c2438671afb1d100603b18df5673cc0bd1f0
BLAKE2b-256 checksum
How to use checksums
191f79ee2acf0f2195ff05a12cbdfeba995d24b68e4a027efe042ea807773d46
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.26

Security for ragdict 0.2.1

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.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files No provenance

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