QuivrHQ / quivr

Open-source RAG Framework for building GenAI Second Brains 🧠 Build productivity assistant (RAG) ⚡️🤖 Chat with your docs (PDF, CSV, ...) & apps using Langchain, GPT 3.5 / 4 turbo, Private, Anthropic, VertexAI, Ollama, LLMs, Groq that you can share with users ! Efficient retrieval augmented generation framework
https://quivr.com
Other
34.35k stars 3.36k forks source link

[Bug]: How to use the embedding model of ollama #2588

Closed wwjCMP closed 2 months ago

wwjCMP commented 2 months ago

What happened?

def get_embeddings(): settings = BrainSettings() # pyright: ignore reportPrivateUsage=none if settings.ollama_api_base_url: embeddings = OllamaEmbeddings( model="ollama/nomic-embed-text:latest" ) # pyright: ignore reportPrivateUsage=none else: embeddings = OpenAIEmbeddings() # pyright: ignore reportPrivateUsage=none return embeddings

I have set it as above, but the following error occurred:

Relevant log output

2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/uvicorn/protocols/http/httptools_impl.py", line 411, in run_asgi
2024-05-14 00:02:24     result = await app(  # type: ignore[func-returns-value]
2024-05-14 00:02:24              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/uvicorn/middleware/proxy_headers.py", line 69, in __call__
2024-05-14 00:02:24     return await self.app(scope, receive, send)
2024-05-14 00:02:24            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 1054, in __call__
2024-05-14 00:02:24     await super().__call__(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 123, in __call__
2024-05-14 00:02:24     await self.middleware_stack(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 186, in __call__
2024-05-14 00:02:24     raise exc
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 164, in __call__
2024-05-14 00:02:24     await self.app(scope, receive, _send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 93, in __call__
2024-05-14 00:02:24     await self.simple_response(scope, receive, send, request_headers=headers)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 148, in simple_response
2024-05-14 00:02:24     await self.app(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 65, in __call__
2024-05-14 00:02:24     await wrap_app_handling_exceptions(self.app, conn)(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
2024-05-14 00:02:24     raise exc
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
2024-05-14 00:02:24     await app(scope, receive, sender)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 756, in __call__
2024-05-14 00:02:24     await self.middleware_stack(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 776, in app
2024-05-14 00:02:24     await route.handle(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 297, in handle
2024-05-14 00:02:24     await self.app(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 77, in app
2024-05-14 00:02:24     await wrap_app_handling_exceptions(app, request)(scope, receive, send)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 64, in wrapped_app
2024-05-14 00:02:24     raise exc
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/_exception_handler.py", line 53, in wrapped_app
2024-05-14 00:02:24     await app(scope, receive, sender)
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 72, in app
2024-05-14 00:02:24     response = await func(request)
2024-05-14 00:02:24                ^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 278, in app
2024-05-14 00:02:24     raw_response = await run_endpoint_function(
2024-05-14 00:02:24                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 191, in run_endpoint_function
2024-05-14 00:02:24     return await dependant.call(**values)
2024-05-14 00:02:24            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/code/modules/brain/controller/brain_routes.py", line 103, in create_new_brain
2024-05-14 00:02:24     new_brain = brain_service.create_brain(
2024-05-14 00:02:24                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/code/modules/brain/service/brain_service.py", line 142, in create_brain
2024-05-14 00:02:24     return self.create_brain_integration(user_id, brain)
2024-05-14 00:02:24            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/code/modules/brain/service/brain_service.py", line 192, in create_brain_integration
2024-05-14 00:02:24     created_brain = self.brain_repository.create_brain(brain)
2024-05-14 00:02:24                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/code/modules/brain/repository/brains.py", line 22, in create_brain
2024-05-14 00:02:24     embeddings = get_embeddings()
2024-05-14 00:02:24                  ^^^^^^^^^^^^^^^^
2024-05-14 00:02:24   File "/code/models/settings.py", line 164, in get_embeddings
2024-05-14 00:02:24     )  # pyright: ignore reportPrivateUsage=none
2024-05-14 00:02:24               ^^^^
2024-05-14 00:02:24 NameError: name 'self' is not defined

Twitter / LinkedIn details

No response

dosubot[bot] commented 2 months ago

The error NameError: name 'self' is not defined suggests there's a problem with how self is used in your code. In Python, self is used within class methods to refer to the instance of the class. If you're seeing this error, it likely means self is being used outside of a class method or in a context where it's not defined.

From the code snippet you shared, self is not explicitly used, which indicates the issue might be in another part of your code not shown here. It's important to ensure that self is only used within class instance methods.

Additionally, the instantiation of OllamaEmbeddings in your code does not show a misuse of self, but make sure the parameters you're passing (like model="ollama/nomic-embed-text:latest") match the expected parameters of the OllamaEmbeddings class. Specifically, if OllamaEmbeddings expects a base_url parameter, ensure you're providing it correctly.

If the problem persists, please provide more context or the specific part of the code where self is used, along with any additional error messages or tracebacks. This will help in diagnosing the issue more accurately.

#### Details **Sources** - [backend/models/settings.py](https://github.com/QuivrHQ/quivr/blob/main/backend/models/settings.py) - [backend/modules/brain/rags/quivr_rag.py](https://github.com/QuivrHQ/quivr/blob/main/backend/modules/brain/rags/quivr_rag.py) - [backend/packages/embeddings/vectors.py](https://github.com/QuivrHQ/quivr/blob/main/backend/packages/embeddings/vectors.py) - [backend/main.py](https://github.com/QuivrHQ/quivr/blob/main/backend/main.py)
**About Dosu** This response is meant to be useful and save you time. It is **not meant to be a precise solution**, but rather a starting point for your own research. Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

wwjCMP commented 2 months ago

https://github.com/QuivrHQ/quivr/issues?q=llama2