TheAiSingularity / graphrag-local-ollama

Local models support for Microsoft's graphrag using ollama (llama3, mistral, gemma2 phi3)- LLM & Embedding extraction
MIT License
577 stars 79 forks source link

--method local #10

Open sunil-thapa99 opened 1 month ago

sunil-thapa99 commented 1 month ago

I'm getting an error as ZeroDivisionError while using --method local. It works for --method global.

(graphrag) sunilthapa@Sunils-MacBook-Air GraphRAG % python -m graphrag.query --root ./ragtest --method local "What is max pooling layer?"

INFO: Reading settings from ragtest/settings.yaml [2024-07-10T03:01:48Z WARN lance::dataset] No existing dataset at /Users/sunilthapa/Desktop/projects/GraphRAG/lancedb/description_embedding.lance, it will be created creating llm client with {'api_key': 'REDACTED,len=9', 'type': "openai_chat", 'model': 'llama3', 'max_tokens': 4000, 'request_timeout': 180.0, 'api_base': 'http://localhost:11434/v1', 'api_version': None, 'organization': None, 'proxy': None, 'cognitive_services_endpoint': None, 'deployment_name': None, 'model_supports_json': True, 'tokens_per_minute': 0, 'requests_per_minute': 0, 'max_retries': 10, 'max_retry_wait': 10.0, 'sleep_on_rate_limit_recommendation': True, 'concurrent_requests': 25} creating embedding llm client with {'api_key': 'REDACTED,len=9', 'type': "openai_embedding", 'model': 'nomic_embed_text', 'max_tokens': 4000, 'request_timeout': 180.0, 'api_base': 'http://localhost:11434/api', 'api_version': None, 'organization': None, 'proxy': None, 'cognitive_services_endpoint': None, 'deployment_name': None, 'model_supports_json': None, 'tokens_per_minute': 0, 'requests_per_minute': 0, 'max_retries': 10, 'max_retry_wait': 10.0, 'sleep_on_rate_limit_recommendation': True, 'concurrent_requests': 25} Error embedding chunk {'OpenAIEmbedding': 'Error code: 404 - {\'error\': "model \'nomic_embed_text\' not found, try pulling it first"}'} Traceback (most recent call last): File "", line 198, in _run_module_as_main File "", line 88, in _run_code File "/opt/anaconda3/envs/graphrag/lib/python3.12/site-packages/graphrag/query/main.py", line 75, in run_local_search( File "/opt/anaconda3/envs/graphrag/lib/python3.12/site-packages/graphrag/query/cli.py", line 154, in run_local_search result = search_engine.search(query=query) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/graphrag/lib/python3.12/site-packages/graphrag/query/structured_search/local_search/search.py", line 118, in search context_text, context_records = self.context_builder.build_context( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/graphrag/lib/python3.12/site-packages/graphrag/query/structured_search/local_search/mixed_context.py", line 139, in build_context selected_entities = map_query_to_entities( ^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/graphrag/lib/python3.12/site-packages/graphrag/query/context_builder/entity_extraction.py", line 55, in map_query_to_entities search_results = text_embedding_vectorstore.similarity_search_by_text( ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/graphrag/lib/python3.12/site-packages/graphrag/vector_stores/lancedb.py", line 118, in similarity_search_by_text query_embedding = text_embedder(text) ^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/graphrag/lib/python3.12/site-packages/graphrag/query/context_builder/entity_extraction.py", line 57, in text_embedder=lambda t: text_embedder.embed(t), ^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/graphrag/lib/python3.12/site-packages/graphrag/query/llm/oai/embedding.py", line 96, in embed chunk_embeddings = np.average(chunk_embeddings, axis=0, weights=chunk_lens) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/opt/anaconda3/envs/graphrag/lib/python3.12/site-packages/numpy/lib/function_base.py", line 550, in average raise ZeroDivisionError( ZeroDivisionError: Weights sum to zero, can't be normalized

dengkeshun commented 1 month ago

@sunil-thapa99 , @TheAiSingularity Did you fix it? I also got this error when using local method query.

sunil-thapa99 commented 1 month ago

@dengkeshun I read some of the raised issues on the official GitHub repository of GraphRag. They seem to be improving GraphRag for Ollama, as of now embedding doesn't seem to work except for only OpenAI.