severian42 / GraphRAG-Local-UI

GraphRAG using Local LLMs - Features robust API and multiple apps for Indexing/Prompt Tuning/Query/Chat/Visualizing/Etc. This is meant to be the ultimate GraphRAG/KG local LLM app.
MIT License
1.51k stars 173 forks source link

Error in embedding_proxy.py #75

Open havvk opened 1 month ago

havvk commented 1 month ago

After running embedding proxy by embedding_proxy.py: python embedding_proxy.py --port 11435 --host http://localhost:11434

I changed the api_base parameter to embedding proxy in settings.yaml :

embeddings:
  async_mode: threaded # or asyncio
  llm:
    api_key: ${GRAPHRAG_API_KEY}
    type: openai_embedding # or azure_openai_embedding
    model: nomic-embed-text:latest
    api_base: http://localhost:11435/v1

Then I tried to run indexing by the new index_app.py, it failed at the end stage.

2024-07-29 22:41:23,311 - api - INFO - ❌ create_final_community_reports
2024-07-29 22:41:23,311 - api - INFO - None
2024-07-29 22:41:23,324 - api - INFO - ⠋ GraphRAG Indexer
2024-07-29 22:41:23,324 - api - INFO - ├── Loading Input (InputFileType.text) - 1 files loaded (0 filtered) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100% 0:00:00 0:00:00
2024-07-29 22:41:23,324 - api - INFO - ├── create_base_text_units
2024-07-29 22:41:23,324 - api - INFO - ├── create_base_extracted_entities
2024-07-29 22:41:23,324 - api - INFO - ├── create_summarized_entities
2024-07-29 22:41:23,324 - api - INFO - ├── create_base_entity_graph
2024-07-29 22:41:23,324 - api - INFO - ├── create_final_entities
2024-07-29 22:41:23,324 - api - INFO - ├── create_final_nodes
2024-07-29 22:41:23,324 - api - INFO - ├── create_final_communities
2024-07-29 22:41:23,324 - api - INFO - ├── join_text_units_to_entity_ids
2024-07-29 22:41:23,324 - api - INFO - ├── create_final_relationships
2024-07-29 22:41:23,324 - api - INFO - ├── join_text_units_to_relationship_ids
2024-07-29 22:41:23,325 - api - INFO - └── create_final_community_reports❌ Errors occurred during the pipeline run, see logs for more details.
2024-07-29 22:41:23,361 - watchfiles.main - INFO - 1 change detected
2024-07-29 22:41:23,646 - api - ERROR - Indexing failed

There are some errors in the embedding proxy:

INFO:     127.0.0.1:51300 - "POST /v1/embeddings HTTP/1.1" 500 Internal Server Error
ERROR:    Exception in ASGI application
Traceback (most recent call last):
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 399, in run_asgi
    result = await app(  # type: ignore[func-returns-value]
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 70, in __call__
    return await self.app(scope, receive, send)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
    await super().__call__(scope, receive, send)
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
    raise exc
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
    await self.app(scope, receive, _send)
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
    await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
    await route.handle(scope, receive, send)
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
    await self.app(scope, receive, send)
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
    await wrap_app_handling_exceptions(app, request)(scope, receive, send)
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
    raise exc
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
    await app(scope, receive, sender)
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/starlette/routing.py", line 72, in app
    response = await func(request)
               ^^^^^^^^^^^^^^^^^^^
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/fastapi/routing.py", line 278, in app
    raw_response = await run_endpoint_function(
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/miniconda3/envs/graphrag/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
    return await dependant.call(**values)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/GraphRAG-Local-UI/embedding_proxy.py", line 44, in create_embedding
    total_tokens += result["usage"]["total_tokens"]
                    ~~~~~~^^^^^^^^^
KeyError: 'usage'

It seems there is no data of usage coming from Ollma (model: nomic-embed-text:latest).

havvk commented 1 month ago

https://github.com/ollama/ollama/blob/main/docs/api.md#generate-embeddings As you can see , there is no usage data from Ollma Embeddings API: image

wrench1997 commented 1 month ago

@havvk My error is similar to yours, probably a format verification error by pydantic.

  return EmbeddingResponse(
      object="list",
      data=embeddings,
      model=request.model, 
      usage={},
  )
JayWu890225 commented 1 month ago

when i use this command to query 'python3 -m graphrag.query --data ./indexing/output/20240802-172944/artifacts --method local --community_level 2 "What are the top themes in this story?"'

Error embedding chunk {'OpenAIEmbedding': "Error code: 422 - {'detail': [{'type': 'string_type', 'loc': ['body', 'input'], 'msg': 'Input should be a valid string', 'input': [3923, 527, 279, 1948, 22100, 304, 420, 3446, 30]}]}"} [] None Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main return _run_code(code, main_globals, None, File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code exec(code, run_globals) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/graphrag/query/main.py", line 76, in run_local_search( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/graphrag/query/cli.py", line 154, in run_local_search result = search_engine.search(query=query) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/graphrag/query/structured_search/local_search/search.py", line 118, in search context_text, context_records = self.context_builder.build_context( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/graphrag/query/structured_search/local_search/mixed_context.py", line 139, in build_context selected_entities = map_query_to_entities( File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/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 "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/graphrag/vector_stores/lancedb.py", line 118, in similarity_search_by_text query_embedding = text_embedder(text) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/graphrag/query/context_builder/entity_extraction.py", line 57, in text_embedder=lambda t: text_embedder.embed(t), File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/graphrag/query/llm/oai/embedding.py", line 103, in embed chunk_embeddings = np.average(chunk_embeddings, axis=0, weights=chunk_lens) File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/numpy/lib/function_base.py", line 550, in average raise ZeroDivisionError( ZeroDivisionError: Weights sum to zero, can't be normalized

It's throw this error.

I saw the input of this embeding is [3923, 527, 279, 1948, 22100, 304, 420, 3446, 30] , not string .

Does anyone face same issue?

sanzhar-rakhimkul commented 1 month ago

@JayWu890225 Did you solve the problem ? I have same issue

itcrazy0918 commented 1 month ago

i also have the problem like : HTTP Request: POST http://localhost:11435/embeddings "HTTP/1.1 404 Not Found"

JayWu890225 commented 1 month ago

@JayWu890225 Did you solve the problem ? I have same issue

actually i did not find root casue of this issue.

I changed some code in embed method - embedding.py.

    for chunk in token_chunks:
        try:
            embedding, chunk_len = self._embed_with_retry(text, **kwargs)
            chunk_embeddings.append(embedding)
            chunk_lens.append(chunk_len)
havvk commented 1 month ago

i also have the problem like : HTTP Request: POST http://localhost:11435/embeddings "HTTP/1.1 404 Not Found"

You should set api_base of embeddings to "http://localhost:11435/v1" in settings.yaml.

sanzhar-rakhimkul commented 1 month ago

@JayWu890225 Did you solve the problem ? I have same issue

actually i did not find root casue of this issue.

I changed some code in embed method - embedding.py.

    for chunk in token_chunks:
        try:
            embedding, chunk_len = self._embed_with_retry(text, **kwargs)
            chunk_embeddings.append(embedding)
            chunk_lens.append(chunk_len)

I found solution here https://github.com/microsoft/graphrag/issues/451#issuecomment-2220861232