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.2.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.2-py3-none-any.whl (12.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dedupkit-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 1a3043438832baf20d192b7710768d2b6bcfe3415fbbd0b015182a976569c83e
MD5 cea25fc95ede384a354a720e1944c877
BLAKE2b-256 2780d11c2e6a9d47ae6a1fa350ba81e38f49525dc5a938e5f464d1034211a12e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dedupkit-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 12.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 be8fe881e637bac2b7a2823f6dbb2dc9bab1953f755afb4d8f39d6d9801211e0
MD5 bfd6625742d4d21f4dae77b873aa5b43
BLAKE2b-256 cdf61655d8b91128ea85f6c4e903febf158fbedf0d633e65503f3e212bc2655c

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