Skip to content
Draft
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
14 changes: 13 additions & 1 deletion src/api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class OnboardingBody(BaseModel):
llm_model: Optional[str] = Field(None, min_length=1)
embedding_provider: Optional[str] = Field(None, pattern="^(openai|watsonx|ollama)$")
embedding_model: Optional[str] = Field(None, min_length=1)
delete_existing_index: Optional[bool] = None
openai_api_key: Optional[str] = Field(None, min_length=1)
anthropic_api_key: Optional[str] = Field(None, min_length=1)
watsonx_api_key: Optional[str] = Field(None, min_length=1)
Expand Down Expand Up @@ -1110,10 +1111,21 @@ async def onboarding(
# Import here to avoid circular imports
from main import init_index_when_ready

# Handle delete_existing_index
delete_existing_index = False
if body.delete_existing_index:
delete_existing_index = True
await TelemetryClient.send_event(
Category.ONBOARDING,
MessageId.ORB_ONBOARD_DELETE_EXISTING_INDEX
)
logger.info("Delete existing index requested during onboarding")

logger.info(
"Initializing OpenSearch index after onboarding configuration"
)
await init_index_when_ready()
await init_index_when_ready(delete_existing=delete_existing_index)

logger.info("OpenSearch index initialization completed successfully")
except Exception as e:
logger.error(
Expand Down
18 changes: 13 additions & 5 deletions src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ async def _ensure_opensearch_index():
# The service can still function, document operations might fail later


async def init_index():
async def init_index(delete_existing: bool = False):
"""Initialize OpenSearch index and security roles"""
try:
await wait_for_opensearch()
Expand All @@ -232,9 +232,17 @@ async def init_index():
endpoint=getattr(embedding_provider_config, "endpoint", None),
)

# Create documents index
index_name = get_index_name()
if not await clients.opensearch.indices.exists(index=index_name):
index_exists = await clients.opensearch.indices.exists(index=index_name)
if index_exists and delete_existing:
# Asked to delete the existing index ..
logger.info(f"Deleting index '{index_name}'...")
resp = await clients.opensearch.indices.delete(index=index_name)
logger.info(f"Deleted index '{index_name}', response: {resp}")
index_exists = False

# Create documents index
if not index_exists:
await clients.opensearch.indices.create(
index=index_name, body=dynamic_index_body
)
Expand Down Expand Up @@ -322,10 +330,10 @@ async def init_index():
raise e


async def init_index_when_ready():
async def init_index_when_ready(delete_existing: bool = False):
"""Wait for the OpenSearch service to be ready and then initialize the OpenSearch index."""
await wait_for_opensearch()
await init_index()
await init_index(delete_existing)


def generate_jwt_keys():
Expand Down
2 changes: 2 additions & 0 deletions src/utils/telemetry/message_id.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ class MessageId:
ORB_ONBOARD_EMBED_MODEL = "ORB_ONBOARD_EMBED_MODEL"
# Message: Sample data ingestion requested
ORB_ONBOARD_SAMPLE_DATA = "ORB_ONBOARD_SAMPLE_DATA"
# Message: Delete existing index requested
ORB_ONBOARD_DELETE_EXISTING_INDEX = "ORB_ONBOARD_DELETE_EXISTING_INDEX"
# Message: Configuration marked as edited
ORB_ONBOARD_CONFIG_EDITED = "ORB_ONBOARD_CONFIG_EDITED"
# Message: Onboarding rolled back due to all files failing
Expand Down
Loading