Skip to content

Commit

Permalink
update memoization + silence unnecessary errors
Browse files Browse the repository at this point in the history
  • Loading branch information
pablonyx committed Dec 4, 2024
1 parent 4f99412 commit 06153fa
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
5 changes: 4 additions & 1 deletion backend/danswer/db/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from sqlalchemy.orm import Session
from sqlalchemy.orm import sessionmaker

from danswer.auth.users import BasicAuthenticationError
from danswer.configs.app_configs import LOG_POSTGRES_CONN_COUNTS
from danswer.configs.app_configs import LOG_POSTGRES_LATENCY
from danswer.configs.app_configs import POSTGRES_API_SERVER_POOL_OVERFLOW
Expand Down Expand Up @@ -426,7 +427,9 @@ def get_session() -> Generator[Session, None, None]:
"""Generate a database session with the appropriate tenant schema set."""
tenant_id = CURRENT_TENANT_ID_CONTEXTVAR.get()
if tenant_id == POSTGRES_DEFAULT_SCHEMA and MULTI_TENANT:
raise HTTPException(status_code=401, detail="User must authenticate")
raise BasicAuthenticationError(
detail="User must authenticate",
)

engine = get_sqlalchemy_engine()

Expand Down
2 changes: 1 addition & 1 deletion backend/danswer/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def log_http_error(_: Request, exc: Exception) -> JSONResponse:

if isinstance(exc, BasicAuthenticationError):
# For BasicAuthenticationError, just log a brief message without stack trace (almost always spam)
logger.error(f"Authentication failed: {str(exc)}")
logger.warning(f"Authentication failed: {str(exc)}")

elif status_code >= 400:
error_msg = f"{str(exc)}\n"
Expand Down
41 changes: 22 additions & 19 deletions web/src/app/admin/embeddings/pages/EmbeddingFormPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { usePopup } from "@/components/admin/connectors/Popup";
import { HealthCheckBanner } from "@/components/health/healthcheck";

import { EmbeddingModelSelection } from "../EmbeddingModelSelectionForm";
import { useEffect, useMemo, useState } from "react";
import { useCallback, useEffect, useMemo, useState } from "react";
import Text from "@/components/ui/text";
import { Button } from "@/components/ui/button";
import { ArrowLeft, ArrowRight, WarningCircle } from "@phosphor-icons/react";
Expand Down Expand Up @@ -158,6 +158,26 @@ export default function EmbeddingForm() {
searchSettings?.multipass_indexing !=
advancedEmbeddingDetails.multipass_indexing;

const updateSearch = useCallback(async () => {
if (!selectedProvider) {
return false;
}
const searchSettings = combineSearchSettings(
selectedProvider,
advancedEmbeddingDetails,
rerankingDetails,
selectedProvider.provider_type?.toLowerCase() as EmbeddingProvider | null
);

const response = await updateSearchSettings(searchSettings);
if (response.ok) {
return true;
} else {
setPopup({ message: "Failed to update search settings", type: "error" });
return false;
}
}, [selectedProvider, advancedEmbeddingDetails, rerankingDetails, setPopup]);

const ReIndexingButton = useMemo(() => {
const ReIndexingButtonComponent = ({
needsReIndex,
Expand Down Expand Up @@ -206,7 +226,7 @@ export default function EmbeddingForm() {
};
ReIndexingButtonComponent.displayName = "ReIndexingButton";
return ReIndexingButtonComponent;
}, [needsReIndex]);
}, [needsReIndex, updateSearch]);

if (!selectedProvider) {
return <ThreeDotsLoader />;
Expand All @@ -222,23 +242,6 @@ export default function EmbeddingForm() {
}));
};

const updateSearch = async () => {
const searchSettings = combineSearchSettings(
selectedProvider,
advancedEmbeddingDetails,
rerankingDetails,
selectedProvider.provider_type?.toLowerCase() as EmbeddingProvider | null
);

const response = await updateSearchSettings(searchSettings);
if (response.ok) {
return true;
} else {
setPopup({ message: "Failed to update search settings", type: "error" });
return false;
}
};

const navigateToEmbeddingPage = (changedResource: string) => {
router.push("/admin/configuration/search?message=search-settings");
};
Expand Down

0 comments on commit 06153fa

Please sign in to comment.