Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for dynamic metadata fields in Elasticsearch index creation #14431

Merged
merged 7 commits into from
Jun 28, 2024
Merged
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ def __init__(
batch_size: int = 200,
distance_strategy: Optional[DISTANCE_STRATEGIES] = "COSINE",
retrieval_strategy: Optional[AsyncRetrievalStrategy] = None,
metadata_mappings: Optional[Dict[str, Dict[str, str]]] = None,
**kwargs,
) -> None:
nest_asyncio.apply()

Expand All @@ -232,12 +234,15 @@ def __init__(
distance=DistanceMetric[distance_strategy]
)

metadata_mappings = {
base_metadata_mappings = {
"document_id": {"type": "keyword"},
"doc_id": {"type": "keyword"},
"ref_doc_id": {"type": "keyword"},
}

if metadata_mappings is not None:
metadata_mappings.update(base_metadata_mappings)

self._store = AsyncVectorStore(
user_agent=get_user_agent(),
client=es_client,
Expand Down Expand Up @@ -296,7 +301,11 @@ def add(
BulkIndexError: If AsyncElasticsearch async_bulk indexing fails.
"""
return asyncio.get_event_loop().run_until_complete(
self.async_add(nodes, create_index_if_not_exists=create_index_if_not_exists)
self.async_add(
nodes,
create_index_if_not_exists=create_index_if_not_exists,
**add_kwargs,
)
)

async def async_add(
Expand Down
Loading