Fulltext
OpenSearch implementation of fulltext search and CRUD capability.
OpenSearchFulltextCapability(index_name, client, query_field='text', encryption=None, default_batch_size=None)
Bases: ElasticLikeCore, BaseFulltextCapability
OpenSearch implementation of FulltextCapability protocol.
This class provides document CRUD operations and flexible querying using OpenSearch.
Attributes:
| Name | Type | Description |
|---|---|---|
index_name |
str
|
The name of the OpenSearch index. |
client |
AsyncOpenSearch
|
AsyncOpenSearch client. |
query_field |
str
|
The field name to use for text content. |
Initialize the OpenSearch fulltext capability.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
index_name
|
str
|
The name of the OpenSearch index. |
required |
client
|
AsyncOpenSearch
|
The OpenSearch client. |
required |
query_field
|
str
|
The field name to use for text content. Defaults to "text". |
'text'
|
encryption
|
EncryptionCapability | None
|
Encryption capability. Defaults to None. |
None
|
default_batch_size
|
int | None
|
Default batch size. Defaults to None. |
None
|
delete_by_id(id_, **kwargs)
async
Deletes records from the data store based on IDs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
id_
|
str | list[str]
|
The ID or list of IDs to delete. |
required |
**kwargs
|
Any
|
Additional arguments. |
{}
|
get_size()
async
Returns the total number of documents in the index.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The total number of documents in the index. |
retrieve(strategy=SupportedQueryMethods.BY_FIELD, query=None, filters=None, options=None, **kwargs)
async
retrieve(strategy: Literal[SupportedQueryMethods.BY_FIELD] | None = SupportedQueryMethods.BY_FIELD, query: str | None = None, filters: FilterClause | QueryFilter | None = None, options: QueryOptions | None = None, **kwargs: Any) -> list[Chunk]
retrieve(strategy: Literal[SupportedQueryMethods.BM25], query: str, filters: FilterClause | QueryFilter | None = None, options: QueryOptions | None = None, k1: float | None = None, b: float | None = None, **kwargs: Any) -> list[Chunk]
retrieve(strategy: Literal[SupportedQueryMethods.AUTOCOMPLETE], query: str, field: str, size: int = 20, fuzzy_tolerance: int = 1, min_prefix_length: int = 3, filter_query: dict[str, Any] | None = None, **kwargs: Any) -> list[str]
retrieve(strategy: Literal[SupportedQueryMethods.AUTOSUGGEST], query: str, search_fields: list[str], autocomplete_field: str, size: int = 20, min_length: int = 3, filter_query: dict[str, Any] | None = None, **kwargs: Any) -> list[str]
retrieve(strategy: Literal[SupportedQueryMethods.SHINGLES], query: str, field: str, size: int = 20, min_length: int = 3, max_length: int = 30, filter_query: dict[str, Any] | None = None, **kwargs: Any) -> list[str]
Public implementation for retrieving records from the datastore.
This method supports multiple retrieval strategies including fulltext search (BM25), metadata filtering (BY_FIELD), and autocomplete/autosuggest features. It handles validation and dispatching to the appropriate internal method.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
strategy
|
SupportedQueryMethods
|
The retrieval strategy to use. Defaults to BY_FIELD. |
BY_FIELD
|
query
|
str | None
|
The query string for text-based strategies. Required for strategies other than BY_FIELD. |
None
|
filters
|
FilterClause | QueryFilter | None
|
Query filters to restrict the search results. |
None
|
options
|
QueryOptions | None
|
Query options for sorting, pagination, and field selection. |
None
|
**kwargs
|
Any
|
Additional strategy-specific parameters passed to the implementation. |
{}
|
Returns:
| Type | Description |
|---|---|
list[Chunk] | list[str]
|
list[Chunk] | list[str]: A list of Chunks for document retrieval strategies, or a list of strings for suggestion strategies (autocomplete, autosuggest, shingles). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the query is missing for strategies that require it, or if an unsupported strategy is provided. |
SupportedQueryMethods
Bases: StrEnum
Supported query methods for OpenSearch fulltext capability.