feat: added elasticsearch connector

This commit is contained in:
Anish Sarkar 2025-10-12 09:39:04 +05:30
parent 402039f02f
commit 55d752e3c8
27 changed files with 4331 additions and 2499 deletions

View file

@ -488,6 +488,25 @@ async def fetch_documents_by_ids(
)
url = metadata.get("url", "")
elif doc_type == "ELASTICSEARCH_CONNECTOR":
# Prefer explicit title in metadata/source, otherwise fallback to doc.title
es_title = (
metadata.get("title")
or metadata.get("es_title")
or doc.title
or f"Elasticsearch: {metadata.get('elasticsearch_index', '')}"
)
title = es_title
description = metadata.get("description") or (
doc.content[:100] + "..."
if len(doc.content) > 100
else doc.content
)
# If a link or index info is stored, surface it
url = metadata.get("url", "") or metadata.get(
"elasticsearch_index", ""
)
else: # FILE and other types
title = doc.title
description = (
@ -512,6 +531,7 @@ async def fetch_documents_by_ids(
"SLACK_CONNECTOR": "Slack (Selected)",
"NOTION_CONNECTOR": "Notion (Selected)",
"GITHUB_CONNECTOR": "GitHub (Selected)",
"ELASTICSEARCH_CONNECTOR": "Elasticsearch (Selected)",
"YOUTUBE_VIDEO": "YouTube Videos (Selected)",
"DISCORD_CONNECTOR": "Discord (Selected)",
"JIRA_CONNECTOR": "Jira Issues (Selected)",
@ -1266,6 +1286,33 @@ async def fetch_relevant_documents(
}
)
elif connector == "ELASTICSEARCH_CONNECTOR":
(
source_object,
elasticsearch_chunks,
) = await connector_service.search_elasticsearch(
user_query=reformulated_query,
user_id=user_id,
search_space_id=search_space_id,
top_k=top_k,
search_mode=search_mode,
)
# Add to sources and raw documents
if source_object:
all_sources.append(source_object)
all_raw_documents.extend(elasticsearch_chunks)
# Stream found document count
if streaming_service and writer:
writer(
{
"yield_value": streaming_service.format_terminal_info_delta(
f"🔎 Found {len(elasticsearch_chunks)} Elasticsearch chunks related to your query"
)
}
)
except Exception as e:
logging.error("Error in search_airtable: %s", traceback.format_exc())
error_message = f"Error searching connector {connector}: {e!s}"