Skip to main content

Semantic deduplication using embeddings

Project description

DedupKit

Semantic deduplication using embeddings.

Python 3.10+ License: MIT

DedupKit detects duplicate or similar text using semantic embeddings. Unlike keyword matching, it understands meaning — so "Login button is broken" matches "Can't sign in".

Installation

# Core with local embeddings
pip install dedupkit[local]

# With OpenAI embeddings
pip install dedupkit[openai]

# With PostgreSQL storage
pip install dedupkit[postgres]

# Everything
pip install dedupkit[all]

Quick Start

from dedupkit import Deduplicator
from dedupkit.providers import LocalEmbeddingProvider
from dedupkit.storage import MemoryStorage

dedup = Deduplicator(
    embedding=LocalEmbeddingProvider(),
    storage=MemoryStorage(),
    threshold=0.85
)

# Add items
dedup.add("Login button is broken", item_id="BUG-001")
dedup.add("Payment form crashes", item_id="BUG-002")

# Check for duplicates
result = dedup.check("Login button not working")
print(result.is_duplicate)           # True
print(result.matches[0].id)          # BUG-001
print(result.matches[0].similarity)  # 0.92

Providers

Local (no API key needed):

from dedupkit.providers import LocalEmbeddingProvider

provider = LocalEmbeddingProvider()

OpenAI:

from dedupkit.providers import OpenAIProvider

provider = OpenAIProvider(api_key="sk-...")

Storage Backends

In-Memory (development):

from dedupkit.storage import MemoryStorage

storage = MemoryStorage()

PostgreSQL + pgvector (production):

from dedupkit.storage import PostgresStorage

storage = await PostgresStorage.create(
    connection_string="postgresql://user:pass@localhost:5432/db",
    dimensions=384  # Must match embedding provider
)

Async Support

For production applications, use AsyncDeduplicator with PostgreSQL:

import asyncio
from dedupkit import AsyncDeduplicator
from dedupkit.providers import LocalEmbeddingProvider
from dedupkit.storage import PostgresStorage

async def main():
    storage = await PostgresStorage.create(
        connection_string="postgresql://user:pass@localhost:5432/db",
        dimensions=384
    )
    
    dedup = AsyncDeduplicator(
        embedding=LocalEmbeddingProvider(),
        storage=storage,
        threshold=0.85
    )
    
    await dedup.add("Login button is broken", item_id="BUG-001")
    
    result = await dedup.check("Can't sign in")
    print(result.is_duplicate)  # True
    
    await storage.close()

asyncio.run(main())

API Reference

Deduplicator / AsyncDeduplicator

Method Description Returns
add(text, item_id?, metadata?) Add item to index str
check(text, threshold?) Check for duplicates DedupResult
remove(item_id) Remove item bool
len() / count() Number of items int

DedupResult

DedupResult(
    is_duplicate: bool,        # True if matches found above threshold
    matches: list[SearchHit]   # Similar items, sorted by similarity
)

SearchHit

SearchHit(
    id: str,              # Item ID
    similarity: float,    # Similarity score (0.0 - 1.0)
    metadata: dict | None # Optional metadata
)

Error Handling

from dedupkit.exceptions import ValidationError, StorageError

try:
    dedup.add("")  # Empty text
except ValidationError as e:
    print(f"Invalid input: {e}")

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dedupkit-0.1.1.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

dedupkit-0.1.1-py3-none-any.whl (12.0 kB view details)

Uploaded Python 3

File details

Details for the file dedupkit-0.1.1.tar.gz.

File metadata

  • Download URL: dedupkit-0.1.1.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for dedupkit-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d3cf7cd66e7a0a56d6e3343238d8dbbc9493721434a5c5a1c0a35d1143e4f6b0
MD5 9b3118a1cdbd5cec1be4e46c214e0392
BLAKE2b-256 01255e12f6b257f27e78fb22b2d23df9d4fe680c104ac2817fb32af0bfb6e7a0

See more details on using hashes here.

File details

Details for the file dedupkit-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: dedupkit-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for dedupkit-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9484fa8d817989c10d8ab537eb210e722f4223c44e1fdee6538986fbacdef83a
MD5 e2c7d1d8ccd9c493811d68e8d2042768
BLAKE2b-256 ed7ae903e46164ff02b366017ceba9c5135eb6bfae782d85890285704f645a3f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page