Skip to content

'OllamaEmbedding' object has no attribute 'dimensions' #69

Description

@hsbdkdn

I intended to execute the instruction python main.py -opt Option/Method/RAPTOR.yaml -dataset_name HotpotQA, but an error occurred. The traceback information is as follows:

Traceback (most recent call last):
  File "/home/ldy/GraphRAG/main.py", line 77, in <module>
    asyncio.run(digimon.insert(corpus))
  File "/opt/conda/envs/digimon/lib/python3.10/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/opt/conda/envs/digimon/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/home/ldy/GraphRAG/Core/GraphRAG.py", line 243, in insert
    await self.entities_vdb.build_index(await self.graph.nodes_data(),node_metadata, False)
  File "/home/ldy/GraphRAG/Core/Index/BaseIndex.py", line 26, in build_index
    await self._update_index(elements, meta_data)
  File "/home/ldy/GraphRAG/Core/Index/FaissIndex.py", line 83, in _update_index
    vector_store = FaissVectorStore(faiss_index=faiss.IndexHNSWFlat(self.embedding_model.dimensions, 32))
  File "/opt/conda/envs/digimon/lib/python3.10/site-packages/pydantic/main.py", line 984, in __getattr__
    raise AttributeError(f'{type(self).__name__!r} object has no attribute {item!r}')
AttributeError: 'OllamaEmbedding' object has no attribute 'dimensions'

To address this issue, I attempted to add code to the _try_set_model_and_batch_size function as follows:

def _try_set_model_and_batch_size(params: dict, config):
    """Set the model_name and embed_batch_size only when they are specified."""
    if config.embedding.model:
        params["model_name"] = config.embedding.model

    if config.embedding.embed_batch_size:
        params["embed_batch_size"] = config.embedding.embed_batch_size

    if config.embedding.dimensions:
        params["dimensions"] = config.embedding.dimensions
        print(f"setting dimensions for model is {params['dimensions']}") # **the added code**

def _raise_for_key(self, key: Any):
    raise ValueError(f"The embedding type is currently not supported: `{type(key)}`, {key}")

Although the output "setting dimensions for model is 1024" was successfully printed, the code still did not execute correctly and the aforementioned error persisted.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions