Skip to content
Merged
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
24 changes: 12 additions & 12 deletions elasticsearch/helpers/vectorstore/_async/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def needs_inference(self) -> bool:


class AsyncSparseVectorStrategy(AsyncRetrievalStrategy):
"""Sparse retrieval strategy using the `text_expansion` processor."""
"""Sparse retrieval strategy using the `sparse_vector` processor."""

def __init__(self, model_id: str = ".elser_model_2"):
self.model_id = model_id
Expand Down Expand Up @@ -127,11 +127,10 @@ def es_query(
"bool": {
"must": [
{
"text_expansion": {
f"{vector_field}.{self._tokens_field}": {
"model_id": self.model_id,
"model_text": query,
}
"sparse_vector": {
"field": f"{vector_field}.{self._tokens_field}",
"inference_id": self.model_id,
"query": query,
}
}
],
Expand All @@ -150,7 +149,7 @@ def es_mappings_settings(
mappings: Dict[str, Any] = {
"properties": {
vector_field: {
"properties": {self._tokens_field: {"type": "rank_features"}}
"properties": {self._tokens_field: {"type": "sparse_vector"}}
}
}
}
Expand All @@ -172,11 +171,12 @@ async def before_index_creation(
{
"inference": {
"model_id": self.model_id,
"target_field": vector_field,
"field_map": {text_field: "text_field"},
"inference_config": {
"text_expansion": {"results_field": self._tokens_field}
},
"input_output": [
{
"input_field": text_field,
"output_field": f"{vector_field}.{self._tokens_field}",
},
],
}
}
],
Expand Down
24 changes: 12 additions & 12 deletions elasticsearch/helpers/vectorstore/_sync/strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def needs_inference(self) -> bool:


class SparseVectorStrategy(RetrievalStrategy):
"""Sparse retrieval strategy using the `text_expansion` processor."""
"""Sparse retrieval strategy using the `sparse_vector` processor."""

def __init__(self, model_id: str = ".elser_model_2"):
self.model_id = model_id
Expand Down Expand Up @@ -127,11 +127,10 @@ def es_query(
"bool": {
"must": [
{
"text_expansion": {
f"{vector_field}.{self._tokens_field}": {
"model_id": self.model_id,
"model_text": query,
}
"sparse_vector": {
"field": f"{vector_field}.{self._tokens_field}",
"inference_id": self.model_id,
"query": query,
}
}
],
Expand All @@ -150,7 +149,7 @@ def es_mappings_settings(
mappings: Dict[str, Any] = {
"properties": {
vector_field: {
"properties": {self._tokens_field: {"type": "rank_features"}}
"properties": {self._tokens_field: {"type": "sparse_vector"}}
}
}
}
Expand All @@ -172,11 +171,12 @@ def before_index_creation(
{
"inference": {
"model_id": self.model_id,
"target_field": vector_field,
"field_map": {text_field: "text_field"},
"inference_config": {
"text_expansion": {"results_field": self._tokens_field}
},
"input_output": [
{
"input_field": text_field,
"output_field": f"{vector_field}.{self._tokens_field}",
},
],
}
}
],
Expand Down
Loading