Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: introducing Ollama embeddings properties. #2690

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ OPENAI_API_KEY=CHANGE_ME

# LOCAL
# OLLAMA_API_BASE_URL=http://host.docker.internal:11434 # Uncomment to activate ollama. This is the local url for the ollama api
# OLLAMA_EMBEDDINGS_MODEL=
# OLLAMA_EMBEDDINGS_DOC_INSTRUCT=
# OLLAMA_EMBEDDINGS_QUERY_INSTRUCT=

########
# FRONTEND
Expand Down
6 changes: 6 additions & 0 deletions backend/models/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class BrainSettings(BaseSettings):
resend_api_key: str = "null"
resend_email_address: str = "[email protected]"
ollama_api_base_url: str = None
ollama_embeddings_model: str = None,
ollama_embeddings_doc_instruct: str = None,
ollama_embeddings_query_instruct: str = None,
langfuse_public_key: str = None
langfuse_secret_key: str = None
pg_database_url: str = None
Expand Down Expand Up @@ -161,6 +164,9 @@ def get_embeddings():
if settings.ollama_api_base_url:
embeddings = OllamaEmbeddings(
base_url=settings.ollama_api_base_url,
model=settings.ollama_embeddings_model,
embed_instruction=settings.ollama_embeddings_doc_instruct,
query_instruction=settings.ollama_embeddings_query_instruct,
) # pyright: ignore reportPrivateUsage=none
else:
embeddings = OpenAIEmbeddings() # pyright: ignore reportPrivateUsage=none
Expand Down
7 changes: 2 additions & 5 deletions backend/modules/brain/rags/quivr_rag.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from langchain.schema import format_document
from langchain_cohere import CohereRerank
from langchain_community.chat_models import ChatLiteLLM
from langchain_community.embeddings import OllamaEmbeddings
from langchain_core.output_parsers import StrOutputParser
from langchain_core.prompts import ChatPromptTemplate, PromptTemplate
from langchain_core.pydantic_v1 import BaseModel as BaseModelV1
Expand All @@ -21,7 +20,7 @@
from langchain_openai import ChatOpenAI, OpenAIEmbeddings
from logger import get_logger
from models import BrainSettings # Importing settings related to the 'brain'
from models.settings import get_supabase_client
from models.settings import get_supabase_client, get_embeddings
from modules.brain.service.brain_service import BrainService
from modules.chat.service.chat_service import ChatService
from modules.knowledge.repository.knowledges import Knowledges
Expand Down Expand Up @@ -153,9 +152,7 @@ class QuivrRAG(BaseModel):
@property
def embeddings(self):
if self.brain_settings.ollama_api_base_url:
return OllamaEmbeddings(
base_url=self.brain_settings.ollama_api_base_url
) # pyright: ignore reportPrivateUsage=none
return get_embeddings()
else:
return OpenAIEmbeddings()

Expand Down
7 changes: 2 additions & 5 deletions backend/modules/chat/controller/chat_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

from fastapi import APIRouter, Depends, HTTPException, Query, Request
from fastapi.responses import StreamingResponse
from langchain_community.embeddings import OllamaEmbeddings
from langchain_openai import OpenAIEmbeddings
from logger import get_logger
from middlewares.auth import AuthBearer, get_current_user
from models.settings import BrainSettings, get_supabase_client
from models.settings import BrainSettings, get_supabase_client, get_embeddings
from modules.brain.service.brain_service import BrainService
from modules.chat.controller.chat.brainful_chat import BrainfulChat
from modules.chat.dto.chats import ChatItem, ChatQuestion
Expand Down Expand Up @@ -40,9 +39,7 @@ def init_vector_store(user_id: UUID) -> CustomSupabaseVectorStore:
supabase_client = get_supabase_client()
embeddings = None
if brain_settings.ollama_api_base_url:
embeddings = OllamaEmbeddings(
base_url=brain_settings.ollama_api_base_url
) # pyright: ignore reportPrivateUsage=none
embeddings = get_embeddings()
else:
embeddings = OpenAIEmbeddings()
vector_store = CustomSupabaseVectorStore(
Expand Down
3 changes: 3 additions & 0 deletions docs/install.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ You can find the installation video [here](https://www.youtube.com/watch?v=cXBa6
> OLLAMA_API_BASE_URL
> Run the following command to start Ollama: `ollama run llama2`
> You can find more information about Ollama [here](https://ollama.ai/).
> Also you need to rename `backend/supabase/migrations/local_20240107152745_ollama.sql` removing `local_` prefix.
> You either need to rename it before starting supabase or run supabase migration after renaming.
> Check `.env.example` comments regarding choosing another embeddings model in Ollama

- **Step 4**: Launch the project

Expand Down
Loading