Skip to content
Open
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
1 change: 1 addition & 0 deletions backend/src/agents/retriever_typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AgentState(TypedDict):
tools: list[str]
sources: Annotated[list[str], add_messages]
urls: Annotated[list[str], add_messages]
context_list: Annotated[list[str], add_messages]
chat_history: str
agent_type: list[str]
mcp_response: Annotated[list[AnyMessage], add_messages]
7 changes: 6 additions & 1 deletion backend/src/api/routers/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
if not GOOGLE_API_KEY:
raise RuntimeError("GOOGLE_API_KEY is not set")

model = "gemini-2.0-flash"
GEMINI_MODEL_MAP = {
"2.0_flash": "gemini-2.0-flash",
"2.5_flash": "gemini-2.5-flash",
"2.5_pro": "gemini-2.5-pro",
}
model = GEMINI_MODEL_MAP.get(os.getenv("GOOGLE_GEMINI", "2.0_flash"), "gemini-2.0-flash")
client = OpenAI(
base_url="https://generativelanguage.googleapis.com/v1beta/openai/",
api_key=GOOGLE_API_KEY,
Expand Down
2 changes: 1 addition & 1 deletion backend/src/prompts/prompt_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
You must not ask the user to refer to the context in any part of your answer.
You must not ask the user to refer to a link that is not a part of your answer.

If there is nothing in the context relevant to the question, simply say "Sorry its not avaiable in my knowledge base."
If there is nothing in the context relevant to the question, simply say "Sorry, it's not available in my knowledge base."
Do not try to make up an answer.
Anything between the following `context` html blocks is retrieved from a knowledge bank, not part of the conversation with the user.

Expand Down
1 change: 1 addition & 0 deletions backend/src/tools/process_pdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def process_pdf_docs(file_path: str) -> list[Document]:
documents = loader.load_and_split(text_splitter=text_splitter)
except PdfStreamError:
logging.error(f"Error processing PDF: {file_path} is corrupted or incomplete.")
return []

for doc in documents:
try:
Expand Down
5 changes: 4 additions & 1 deletion backend/src/vectorstores/faiss.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,12 @@ def add_documents(
return None

def get_db_path(self) -> str:
env_path = os.getenv("FAISS_DB_PATH")
if env_path:
return os.path.abspath(env_path)
cur_path = os.path.abspath(__file__)
path = os.path.join(cur_path, "../../../", "faiss_db")
path = os.path.abspath(path) # Ensure proper parent directory
path = os.path.abspath(path)
return path

def save_db(self, name: str) -> None:
Expand Down
19 changes: 17 additions & 2 deletions backend/tests/test_faiss_vectorstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,18 +184,33 @@ def test_add_md_docs_invalid_folder_paths(self):
db.add_md_docs(folder_paths="not_a_list")

def test_get_db_path(self):
"""Test get_db_path returns correct path."""
"""Test get_db_path returns correct default path when env var is unset."""
with patch("src.vectorstores.faiss.HuggingFaceEmbeddings") as mock_hf:
mock_hf.return_value = Mock()

db = FAISSVectorDatabase(
embeddings_type="HF", embeddings_model_name="test-model"
)

path = db.get_db_path()
with patch.dict(os.environ, {}, clear=False):
os.environ.pop("FAISS_DB_PATH", None)
path = db.get_db_path()
assert path.endswith("faiss_db")
assert os.path.isabs(path)

def test_get_db_path_from_env(self):
"""Test get_db_path respects FAISS_DB_PATH env var."""
with patch("src.vectorstores.faiss.HuggingFaceEmbeddings") as mock_hf:
mock_hf.return_value = Mock()

db = FAISSVectorDatabase(
embeddings_type="HF", embeddings_model_name="test-model"
)

with patch.dict(os.environ, {"FAISS_DB_PATH": "/tmp/my_faiss"}):
path = db.get_db_path()
assert path == "/tmp/my_faiss"

def test_save_db_without_documents_raises_error(self):
"""Test save_db raises error when no documents in database."""
with patch("src.vectorstores.faiss.HuggingFaceEmbeddings") as mock_hf:
Expand Down