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.0.tar.gz (9.6 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.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: dedupkit-0.1.0.tar.gz
  • Upload date:
  • Size: 9.6 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.0.tar.gz
Algorithm Hash digest
SHA256 15f9ee67103763db30fa193ba35755bf2e6d9be321a3ab39b31ebd3e0bf63fef
MD5 2a78c4ec7f916f469467d42b9f3fc45d
BLAKE2b-256 fda0c0adca147c2e47c029e852b44a3de61ccdcaa684558fe921e584a95e05e7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: dedupkit-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2905f0cb5054b63aa7e099626abf3ff3b225a8a9ed098599bc6b7772fbe071e7
MD5 26398ccfd108a36c6a5374870a9a36a0
BLAKE2b-256 284e8b85791c4e946a2fa43ef93621a5e1042aa5bac5b22b5ca0019cd8168fd8

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