oa.vector_stores

Vector stores and search

Functions

bind_and_modify(func, *bound_args[, ...])

Convenience function that both binds arguments and modifies signature.

docs_to_search_func_factory_via_vector_store(docs)

Factory function that creates a search function via vector store.

docs_to_vector_store(docs[, vs_name, client])

Create an OpenAI vector store from a mapping of documents.

mk_search_func_for_oa_vector_store(...[, ...])

Create a search function for an OpenAI vector store using the Responses API.

oa.vector_stores.bind_and_modify(func, *bound_args, _param_changes=(), **bound_kwargs)[source]

Convenience function that both binds arguments and modifies signature.

This is perfect for your vector store search use case.

Parameters:
  • func – The function to wrap

  • bound_args – Positional arguments to bind

  • bound_kwargs – Dict of argument names to values to bind

  • _param_changes (dict) – Parameter modifications

Returns:

Wrapped function with bound arguments and modified signature

Example for your vector store case:

>>> def search(vector_store_id, *, query, filters=None, max_results=10):
...     return f"Searching {vector_store_id} for '{query}'"
>>>
>>> # Bind vector_store_id and make query positional
>>> bound_search = bind_and_modify(
...     search,
...     vector_store_id='my_store',
...     _param_changes=dict(query={'kind': Parameter.POSITIONAL_OR_KEYWORD}),
... )
>>>
>>> bound_search('my query')
"Searching my_store for 'my query'"
oa.vector_stores.docs_to_search_func_factory_via_vector_store(docs)[source]

Factory function that creates a search function via vector store. This can be used with check_search_func_factory.

Return type:

Callable[[str], Iterable[Any]]

oa.vector_stores.docs_to_vector_store(docs, vs_name=None, *, client=None)[source]

Create an OpenAI vector store from a mapping of documents.

Parameters:
  • docs (Mapping[str, str]) – Mapping of document keys to text content

  • vs_name (str) – Optional name for the vector store. If None, generates a unique name.

Returns:

(vector_store_id, file_id_to_doc_key_mapping)

Return type:

tuple[str, dict[str, str]]

If anything fails after the vector store is created, the store and the files uploaded so far are deleted (best effort) before the error is re-raised.

oa.vector_stores.mk_search_func_for_oa_vector_store(vector_store_id, doc_id_mapping=None, *, client=None)[source]

Create a search function for an OpenAI vector store using the Responses API.

Parameters:
  • vector_store_id (str) – The ID of the vector store to search

  • doc_id_mapping (Mapping[str, str]) – Optional mapping from file IDs to document keys for result translation

Return type:

Callable[[str], Iterable[Any]]

Returns:

A function that takes a query and returns search results