GraphRAG icon indicating copy to clipboard operation
GraphRAG copied to clipboard

'OllamaEmbedding' object has no attribute 'dimensions'

Open hsbdkdn opened this issue 8 months ago • 3 comments

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.

hsbdkdn avatar Apr 11 '25 10:04 hsbdkdn

I also encountered this problem, may I ask how it was ultimately resolved

lytgod avatar Apr 23 '25 07:04 lytgod

@hsbdkdn

lytgod avatar Apr 23 '25 08:04 lytgod

I'm sorry that I don't resolved it ultimately. I decided to use other tools after that.

---Original--- From: @.> Date: Wed, Apr 23, 2025 15:42 PM To: @.>; Cc: @.@.>; Subject: Re: [JayLZhou/GraphRAG] 'OllamaEmbedding' object has no attribute'dimensions' (Issue #69)

I also encountered this problem, may I ask how it was ultimately resolved

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***> lytgod left a comment (JayLZhou/GraphRAG#69)

I also encountered this problem, may I ask how it was ultimately resolved

— Reply to this email directly, view it on GitHub, or unsubscribe. You are receiving this because you authored the thread.Message ID: @.***>

hsbdkdn avatar Apr 24 '25 03:04 hsbdkdn