Skip to main content

A library for embedding, indexing, and applying semantic search for text and image data

Project description

Deep Semantic Search

A Python library for embedding, indexing, and applying semantic search for text and image data.

Features

  • Multi-modal Semantic Search

    • Embed and index text data using Sentence Transformers (paraphrase-multilingual-MiniLM-L12-v2)
    • Embed and index image data using CLIP
    • Search images by image or text queries
    • Search text by semantic similarity
  • Clustering & Captioning

    • Cluster image embeddings using PyTorch KMeans (GPU support)
    • Caption images using BLIP
    • Customizable LLM-powered topic labeling via callback
  • Retrieval-Augmented Generation (RAG)

    • Answer questions based on text data
    • Pluggable LLM via callback pattern

Installation

pip install deep-semantic-search

For development:

pip install deep-semantic-search[dev]

Quick Start

Image Search

from deep_semantic_search import LoadImageData, ImageIndexer, ImageSearcher

# Load images
loader = LoadImageData()
image_paths = loader.from_folder(["path/to/images"])

# Index images
indexer = ImageIndexer(image_paths)
indexer.run_index()

# Search by text
searcher = ImageSearcher(indexer)
results = searcher.search_by_text("cat on a sofa", n=5)
for path, score in results.items():
    print(f"{score:.3f}  {path}")

# Search by image
results = searcher.search_by_image("query.jpg", n=5)

Text Search

from deep_semantic_search import LoadTextData, TextEmbedder, TextSearch

# Load text data
loader = LoadTextData()
corpus = loader.from_folder("path/to/text/files")

# Embed
embedder = TextEmbedder()
embedder.embed(corpus)

# Search
search = TextSearch(embedder)
results = search.find_similar("your search query", top_n=5)
for r in results:
    print(f"Score: {r['score']:.3f}  {r['path']}")

Image Clustering

from deep_semantic_search import ImageIndexer, ImageClusterer, ImageCaptioner

indexer = ImageIndexer(image_paths)
indexer.run_index()

# Optional: use captioner for topic labels
captioner = ImageCaptioner()
clusterer = ImageClusterer(indexer)
result = clusterer.cluster(n_clusters=5, captioner=captioner)

# Save organized clusters to disk
clusterer.save_clusters("./output/clusters")

RAG (Question Answering)

from deep_semantic_search import ask_question

texts = ["Document 1 content...", "Document 2 content..."]
answer = ask_question(texts, "What is the main topic?")
print(answer)

# With a custom LLM
answer = ask_question(texts, "Summarize this.", llm_fn=my_custom_llm)

Custom Data Paths

By default, metadata is stored in ~/.deep-semantic-search/. Override per instance:

indexer = ImageIndexer(image_paths, metadata_dir="./my_project/index")
embedder = TextEmbedder(metadata_dir="./my_project/text_index")

API Reference

Image Module

  • LoadImageData — Load image paths from folders or CSV
  • ImageIndexer — CLIP embedding + FAISS indexing
  • ImageSearcher — Image/text similarity search
  • ImageClusterer — KMeans clustering with topic labeling
  • ImageCaptioner — BLIP image captioning

Text Module

  • LoadTextData — Load text from folders (.txt/.html) or CSV
  • TextEmbedder — Sentence Transformer embeddings
  • TextSearch — Cosine similarity search

RAG

  • ask_question() — RAG Q&A with pluggable LLM

Exceptions

  • DeepSemanticSearchError — Base exception
  • IndexNotFoundError, ModelLoadError, SearchError, EmbeddingError, ClusteringError

CLI Tool

The package includes dss, a command-line interface for all major features. After installing the package, the dss command is available globally.

General Usage

dss --help          # Show all commands
dss --version       # Show version
dss <command> --help  # Help for a specific command

Global flags: -v/--verbose for debug output, -q/--quiet to suppress progress.

Image Search

Search images by text query or by image similarity:

# Search by text
dss image-search --folder ./photos --query "sunset over the ocean" --top 5

# Search by image
dss image-search --folder ./photos --query ./photos/reference.jpg --top 10

# Multiple folders, JSON output
dss image-search -f ./photos -f ./vacation --query "mountains" --format json

# Force re-indexing
dss image-search -f ./photos --query "cat" --reindex

Text Search

Search text documents by semantic similarity:

dss text-search --folder ./documents "machine learning algorithms" --top 5

# CSV output
dss text-search -f ./docs "neural networks" --format csv

# Custom model
dss text-search -f ./docs "query" --model sentence-transformers/all-MiniLM-L6-v2

Image Clustering

Cluster images using KMeans on CLIP embeddings:

# Basic clustering
dss image-cluster --folder ./photos --clusters 5

# With BLIP captioning for topic labels
dss image-cluster -f ./photos -k 5 --caption

# Save clustered images into organized folders
dss image-cluster -f ./photos -k 8 --caption --save-dir ./output/clusters

# JSON output
dss image-cluster -f ./photos -k 3 --format json

RAG (Question Answering)

Ask questions over text documents using Retrieval-Augmented Generation:

dss ask --folder ./documents "What is the main conclusion?"

# Custom Ollama model
dss ask -f ./research "Summarize the findings" --model llama2:13b

# Adjust chunking
dss ask -f ./docs "question" --chunk-size 2000 --chunk-overlap 200

Configuration

The CLI respects environment variables:

  • OLLAMA_LLM_MODEL — LLM model for RAG (default: gemma4:e4b)
  • DEFAULT_SEARCH_FOLDER_PATH — Default folder path

All CLI flags override environment variables when provided.

Requirements

  • Python >= 3.10
  • PyTorch, Sentence Transformers, Transformers, FAISS, LangChain, and more (auto-installed)

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

deep_semantic_search-1.1.2.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

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

deep_semantic_search-1.1.2-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file deep_semantic_search-1.1.2.tar.gz.

File metadata

  • Download URL: deep_semantic_search-1.1.2.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for deep_semantic_search-1.1.2.tar.gz
Algorithm Hash digest
SHA256 1b59f512d1ed7d1312e0917a3fbe70c5ac3bb9a5bc6bff28588a5c949e7d7a0d
MD5 c1f62ba45cb46cc759f2a4200a2d6d79
BLAKE2b-256 e83587bcb58bcbf3ae9643991be1bcfc38bc2d4e34b4de0cddd4c4b1143d17d9

See more details on using hashes here.

Provenance

The following attestation bundles were made for deep_semantic_search-1.1.2.tar.gz:

Publisher: publish.yml on Harduex/deep-semantic-search

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deep_semantic_search-1.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for deep_semantic_search-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8a820766c6964c1ae8d5f3ba39ed9fea4bca10cb6e12c003eee48abd0b69193e
MD5 cdb6fb87458480143c3a92aea471ea7d
BLAKE2b-256 311d3c9827a94d79a42161919bb7a1859e309a8dc2540f5ec2a76961c1b98b61

See more details on using hashes here.

Provenance

The following attestation bundles were made for deep_semantic_search-1.1.2-py3-none-any.whl:

Publisher: publish.yml on Harduex/deep-semantic-search

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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