Skip to content

[Search SDK] Use Sequence type hint instead of List where appropriate #33316

Open
@pamelafox

Description

@pamelafox
  • Package Name: azure-documents-search
  • Package Version: 11.4.0b11
  • Operating System: Mac OS X
  • Python Version: 3.11

Describe the bug

The search() function currently has this signature:

vector_queries: Optional[List[VectorQuery]] = None,

That means if I then have code like:

vectors = []
if has_vector:
    embedding_args = {"deployment_id": self.embedding_deployment} if self.openai_host == "azure" else {}
    embedding = await openai.Embedding.acreate(**embedding_args, model=self.embedding_model, input=query_text)
    query_vector = embedding["data"][0]["embedding"]
    vectors.append(RawVectorQuery(vector=query_vector, k=50, fields="embedding"))

And run mypy, I get a typing error:

backend/approaches/retrievethenread.py:102: error: Argument "vector_queries" to "search" of "SearchClient" has incompatible type "list[RawVectorQuery]"; expected "list[VectorQuery] | None"  [arg-type]
backend/approaches/retrievethenread.py:102: note: "List" is invariant -- see https://mypy.readthedocs.io/en/stable/common_issues.html#variance
backend/approaches/retrievethenread.py:102: note: Consider using "Sequence" instead, which is covariant

I think you could use Sequence in this case, as it's not clear to me that you need it to be a List.

See this related issue:
#29370

Additional context

I am going to workaround like this for now:

vectors: list[VectorQuery] = []

Metadata

Metadata

Assignees

Labels

Searchneeds-team-attentionWorkflow: This issue needs attention from Azure service team or SDK team

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions