Skip to content

faiss_cache.py: from_json() raises TypeError when calling IndexConfig.from_dict() on abstract class #17

@GhazalehNiknam

Description

@GhazalehNiknam

Is there an existing issue for this?

  • I have searched the existing issues

Bug summary

When running omop-emb maintenance import-faiss-cache, the command fails with a TypeError because from_json() in faiss_cache.py calls IndexConfig.from_dict() on the abstract base class directly. Replacing it with index_config_from_index_type() fixes the issue.

Code for reproduction

omop-emb maintenance import-faiss-cache \
  --model "medembed-small-v0.1-local:f16" \
  --cache-dir ~/embeddings/faiss_flat_cosine \
  --provider-type ollama \
  --metric-type cosine \
  --index-type flat

Error messages

╭────────────────────────────────────────────────────────────────────────────────── Traceback (most recent call last) ──────────────────────────────────────────────────────────────────────────────────╮
│ /home/ghazaleh/cava-env/lib/python3.12/site-packages/omop_emb/cli/cli_maintenance.py:369 in import_faiss_cache                                                                                        │
│                                                                                                                                                                                                       │
│   366 │   │   raise typer.Exit(1)                                                                                                                                                                     │
│   367 │                                                                                                                                                                                               │
│   368 │   try:                                                                                                                                                                                        │
│ ❱ 369 │   │   imported = cache.import_to_backend(                                                                                                                                                     │
│   370 │   │   │   backend=backend,                                                                                                                                                                    │
│   371 │   │   │   metric_type=metric_type,                                                                                                                                                            │
│   372 │   │   │   index_config=index_config,                                                                                                                                                          │
│                                                                                                                                                                                                       │
│ /home/ghazaleh/cava-env/lib/python3.12/site-packages/omop_emb/storage/faiss/faiss_cache.py:756 in import_to_backend                                                                                   │
│                                                                                                                                                                                                       │
│   753 │   │   """                                                                                                                                                                                     │
│   754 │   │   from omop_emb.utils.embedding_utils import ConceptEmbeddingRecord                                                                                                                       │
│   755 │   │                                                                                                                                                                                           │
│ ❱ 756 │   │   meta = self._load_meta(metric_type, index_config)                                                                                                                                       │
│   757 │   │                                                                                                                                                                                           │
│   758 │   │   meta_path = self._metadata_path()                                                                                                                                                       │
│   759 │   │   if not meta_path.exists():                                                                                                                                                              │
│                                                                                                                                                                                                       │
│ /home/ghazaleh/cava-env/lib/python3.12/site-packages/omop_emb/storage/faiss/faiss_cache.py:695 in _load_meta                                                                                          │
│                                                                                                                                                                                                       │
│   692 │   │   │   │   f"FAISS index metadata not found at '{json_path}'. "                                                                                                                            │
│   693 │   │   │   │   "Run FAISSCache.export() first."                                                                                                                                                │
│   694 │   │   │   )                                                                                                                                                                                   │
│ ❱ 695 │   │   return CacheMetadata.from_json(json_path.read_text())                                                                                                                                   │
│   696 │                                                                                                                                                                                               │
│   697 │   # ------------------------------------------------------------------                                                                                                                        │
│   698 │   # Import                                                                                                                                                                                    │
│                                                                                                                                                                                                       │
│ /home/ghazaleh/cava-env/lib/python3.12/site-packages/omop_emb/storage/faiss/faiss_cache.py:198 in from_json                                                                                           │
│                                                                                                                                                                                                       │
│   195 │   │   │   model_name=d.get("model_name", ""),                                                                                                                                                 │
│   196 │   │   │   dimensions=int(d.get("dimensions", 0)),                                                                                                                                             │
│   197 │   │   │   metric_type=MetricType(d["metric_type"]),                                                                                                                                           │
│ ❱ 198 │   │   │   index_config=IndexConfig.from_dict(d.get("index_config", {})),                                                                                                                      │
│   199 │   │   │   row_count=int(d.get("row_count", -1)),                                                                                                                                              │
│   200 │   │   │   exported_at=d.get("exported_at", ""),                                                                                                                                               │
│   201 │   │   │   model_updated_at=d.get("model_updated_at"),                                                                                                                                         │
│                                                                                                                                                                                                       │
│ /home/ghazaleh/cava-env/lib/python3.12/site-packages/omop_emb/backends/index_config.py:132 in from_dict                                                                                               │
│                                                                                                                                                                                                       │
│   129 │   │   if not is_dataclass(cls):                                                                                                                                                               │
│   130 │   │   │   raise TypeError(f"Must be called on a dataclass, not {cls.__name__}.")                                                                                                              │
│   131 │   │   if inspect.isabstract(cls):                                                                                                                                                             │
│ ❱ 132 │   │   │   raise TypeError(                                                                                                                                                                    │
│   133 │   │   │   │   f"Cannot instantiate abstract class {cls.__name__} directly. "                                                                                                                  │
│   134 │   │   │   │   "Call on a subclass."                                                                                                                                                           │
│   135 │   │   │   )                                                                                                                                                                                   │
╰───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
TypeError: Cannot instantiate abstract class IndexConfig directly. Call on a subclass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions