diff --git a/backend/danswer/configs/model_configs.py b/backend/danswer/configs/model_configs.py index a0b635566..b8e29f1d9 100644 --- a/backend/danswer/configs/model_configs.py +++ b/backend/danswer/configs/model_configs.py @@ -21,5 +21,5 @@ BATCH_SIZE_ENCODE_CHUNKS = 8 # QA Model API Configs # https://platform.openai.com/docs/models/model-endpoint-compatibility INTERNAL_MODEL_VERSION = os.environ.get("INTERNAL_MODEL", "openai-chat-completion") -OPENAPI_MODEL_VERSION = os.environ.get("OPENAI_MODEL_VERSION", "gpt-4") +OPENAI_MODEL_VERSION = os.environ.get("OPENAI_MODEL_VERSION", "gpt-4") OPENAI_MAX_OUTPUT_TOKENS = 512 diff --git a/backend/danswer/datastores/qdrant/indexing.py b/backend/danswer/datastores/qdrant/indexing.py index 67299acaa..02e61ab72 100644 --- a/backend/danswer/datastores/qdrant/indexing.py +++ b/backend/danswer/datastores/qdrant/indexing.py @@ -18,6 +18,7 @@ from qdrant_client import QdrantClient from qdrant_client.http.exceptions import ResponseHandlingException from qdrant_client.http.models.models import UpdateResult from qdrant_client.http.models.models import UpdateStatus +from qdrant_client.models import CollectionsResponse from qdrant_client.models import Distance from qdrant_client.models import PointStruct from qdrant_client.models import VectorParams @@ -27,6 +28,10 @@ logger = setup_logger() DEFAULT_BATCH_SIZE = 30 +def list_collections() -> CollectionsResponse: + return get_qdrant_client().get_collections() + + def create_collection( collection_name: str, embedding_dim: int = DOC_EMBEDDING_DIM ) -> None: diff --git a/backend/danswer/direct_qa/question_answer.py b/backend/danswer/direct_qa/question_answer.py index 1fcdf4d1b..f232f9e4d 100644 --- a/backend/danswer/direct_qa/question_answer.py +++ b/backend/danswer/direct_qa/question_answer.py @@ -21,7 +21,7 @@ from danswer.configs.constants import SEMANTIC_IDENTIFIER from danswer.configs.constants import SOURCE_LINK from danswer.configs.constants import SOURCE_TYPE from danswer.configs.model_configs import OPENAI_MAX_OUTPUT_TOKENS -from danswer.configs.model_configs import OPENAPI_MODEL_VERSION +from danswer.configs.model_configs import OPENAI_MODEL_VERSION from danswer.direct_qa.interfaces import QAModel from danswer.direct_qa.qa_prompts import ANSWER_PAT from danswer.direct_qa.qa_prompts import get_chat_reflexion_msg @@ -185,7 +185,7 @@ class OpenAICompletionQA(QAModel): def __init__( self, prompt_processor: Callable[[str, list[str]], str] = json_processor, - model_version: str = OPENAPI_MODEL_VERSION, + model_version: str = OPENAI_MODEL_VERSION, max_output_tokens: int = OPENAI_MAX_OUTPUT_TOKENS, ) -> None: self.prompt_processor = prompt_processor @@ -282,7 +282,7 @@ class OpenAIChatCompletionQA(QAModel): prompt_processor: Callable[ [str, list[str]], list[dict[str, str]] ] = json_chat_processor, - model_version: str = OPENAPI_MODEL_VERSION, + model_version: str = OPENAI_MODEL_VERSION, max_output_tokens: int = OPENAI_MAX_OUTPUT_TOKENS, reflexion_try_count: int = 0, ) -> None: diff --git a/backend/danswer/main.py b/backend/danswer/main.py index 714a6a932..3d4694327 100644 --- a/backend/danswer/main.py +++ b/backend/danswer/main.py @@ -10,6 +10,7 @@ from danswer.configs.app_configs import APP_PORT from danswer.configs.app_configs import ENABLE_OAUTH from danswer.configs.app_configs import SECRET from danswer.configs.app_configs import WEB_DOMAIN +from danswer.datastores.qdrant.indexing import list_collections from danswer.server.admin import router as admin_router from danswer.server.event_loading import router as event_processing_router from danswer.server.search_backend import router as backend_router @@ -100,8 +101,11 @@ def get_application() -> FastAPI: from danswer.datastores.qdrant.indexing import create_collection from danswer.configs.app_configs import QDRANT_DEFAULT_COLLECTION - create_collection(collection_name=QDRANT_DEFAULT_COLLECTION) - logger.info("Collection ready") + if QDRANT_DEFAULT_COLLECTION not in { + collection.name for collection in list_collections().collections + }: + logger.info(f"Creating collection with name: {QDRANT_DEFAULT_COLLECTION}") + create_collection(collection_name=QDRANT_DEFAULT_COLLECTION) warm_up_models() logger.info("Semantic Search models are ready.") diff --git a/deployment/env.dev.template b/deployment/env.dev.template index f322a3de9..7387cbd76 100644 --- a/deployment/env.dev.template +++ b/deployment/env.dev.template @@ -9,7 +9,7 @@ OPENAI_API_KEY= INTERNAL_MODEL_VERSION=openai-chat-completion # Use a valid model for the choice above, consult https://platform.openai.com/docs/models/model-endpoint-compatibility -OPENAPI_MODEL_VERSION=gpt-3.5-turbo +OPENAI_MODEL_VERSION=gpt-3.5-turbo # Can leave these as defaults diff --git a/deployment/env.prod.template b/deployment/env.prod.template index 1d35825e0..46df0363c 100644 --- a/deployment/env.prod.template +++ b/deployment/env.prod.template @@ -8,7 +8,7 @@ OPENAI_API_KEY= # Choose between "openai-chat-completion" and "openai-completion" INTERNAL_MODEL_VERSION=openai-chat-completion # Use a valid model for the choice above, consult https://platform.openai.com/docs/models/model-endpoint-compatibility -OPENAPI_MODEL_VERSION=gpt-4 +OPENAI_MODEL_VERSION=gpt-4 # Could be something like danswer.companyname.com. Requires additional setup if not localhost WEB_DOMAIN=http://localhost:3000