Skip to content

Issue building KNN query #72

@anunomac

Description

@anunomac

I am able to build the query and search via opensearch-py but cannot build the query via django-opensearch-dsl.

Example:

Via opensearch-py:

client = OpenSearch(
        hosts=[{"host":host, "port": port}],
        http_auth=auth_cred,
        use_ssl=True,
        verify_certs=False,
        ssl_show_warn=False,
    )
vector=get_embedding("my string")
query={
"query":{"bool":{"must":[],"should":[{"knn":{"content_name_embedding":{"vector":vector,"k":20}}}]}}
}
results = client.search(index=index_name, body=query)

This works and returns hits.
Via django-opensearch-dsl, I've tried multiple setups, they all result in something like:
opensearchpy.exceptions.UnknownDslObject: DSL class 'knn' does not exist in query.
Some of my tries:

s=MyDocument.search().query({"knn": {"content_name_embedding": {"vector": vector, "k": 20}}})
s=MyDocument.search().query(query)
s=MyDocument.search().query(query["query"])

any guidance would be appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions