AzureSearch#
- class langchain_azure_ai.vectorstores.azuresearch.AzureSearch(
- azure_search_endpoint: str,
- azure_search_key: str | None,
- index_name: str,
- embedding_function: Callable | Embeddings,
- search_type: str = 'hybrid',
- semantic_configuration_name: str | None = None,
- fields: List[SearchField] | None = None,
- vector_search: VectorSearch | None = None,
- semantic_configurations: SemanticConfiguration | List[SemanticConfiguration] | None = None,
- scoring_profiles: List[ScoringProfile] | None = None,
- default_scoring_profile: str | None = None,
- cors_options: CorsOptions | None = None,
- *,
- vector_search_dimensions: int | None = None,
- additional_search_client_options: Dict[str, Any] | None = None,
- azure_ad_access_token: str | None = None,
- azure_credential: TokenCredential | None = None,
- azure_async_credential: AsyncTokenCredential | None = None,
- **kwargs: Any,
Azure Cognitive Search vector store.
Initialize the AzureSearch vector store.
- Parameters:
azure_search_endpoint (str) – The endpoint URL for Azure Cognitive Search.
azure_search_key (Optional[str]) – The API key for Azure Cognitive Search.
index_name (str) – The name of the index to use.
embedding_function (Union[Callable, Embeddings]) – The embedding function or object.
search_type (str) – The type of search to perform (default: “hybrid”).
semantic_configuration_name (Optional[str]) – Optional semantic configuration name.
fields (Optional[List[SearchField]]) – Optional list of search fields.
vector_search (Optional[VectorSearch]) – Optional vector search configuration.
semantic_configurations (Optional[Union[SemanticConfiguration, List[SemanticConfiguration]]]) – Optional semantic configurations.
scoring_profiles (Optional[List[ScoringProfile]]) – Optional scoring profiles.
default_scoring_profile (Optional[str]) – Optional default scoring profile.
cors_options (Optional[CorsOptions]) – Optional CORS options.
vector_search_dimensions (Optional[int]) – Optional vector search dimensions.
additional_search_client_options (Optional[Dict[str, Any]]) – Additional options for the search client.
azure_ad_access_token (Optional[str]) – Optional Azure AD access token.
azure_credential (Optional[TokenCredential]) – Optional Azure credential.
azure_async_credential (Optional[AsyncTokenCredential]) – Optional async Azure credential.
**kwargs (Any) – Additional keyword arguments.
Attributes
embeddings
Return the embeddings object if available.
Methods
__init__
(azure_search_endpoint, ...[, ...])Initialize the AzureSearch vector store.
aadd_documents
(documents, **kwargs)Async run more documents through the embeddings and add to the vectorstore.
aadd_embeddings
(text_embeddings[, ...])Add embeddings to an existing index.
aadd_texts
(texts[, metadatas, keys])Asynchronously add texts data to an existing index.
add_documents
(documents, **kwargs)Add or update documents in the vectorstore.
add_embeddings
(text_embeddings[, metadatas, ...])Add embeddings to an existing index.
add_texts
(texts[, metadatas, keys])Add texts data to an existing index.
adelete
([ids])Asynchronously delete by vector ID.
afrom_documents
(documents, embedding, **kwargs)Async return VectorStore initialized from documents and embeddings.
afrom_embeddings
(text_embeddings, embedding)Asynchronously create Azure Search vector store from text embeddings.
afrom_texts
(texts, embedding[, metadatas, ...])Asynchronously create Azure Search vector store from a list of texts.
aget_by_ids
(ids, /)Async get documents by their IDs.
Asynchronously return docs with hybrid query and MMR reordering.
ahybrid_search
(query[, k])Returns the most similar indexed documents to the query text.
Asynchronously return documents and scores above a threshold.
ahybrid_search_with_score
(query[, k, filters])Return docs most similar to query with a hybrid query.
amax_marginal_relevance_search
(query[, k, ...])Async return docs selected using the maximal marginal relevance.
Async return docs selected using the maximal marginal relevance.
Perform a search and return results that are reordered by MMR.
as_retriever
(**kwargs)Return AzureSearchVectorStoreRetriever initialized from this VectorStore.
asearch
(query, search_type, **kwargs)Async return docs most similar to query using a specified search type.
asemantic_hybrid_search
(query[, k])Returns the most similar indexed documents to the query text.
asemantic_hybrid_search_with_score
(query[, ...])Returns the most similar indexed documents to the query text.
Return docs most similar to query with a hybrid query.
asimilarity_search
(query[, k, search_type])Asynchronously return documents most similar to the query.
asimilarity_search_by_vector
(embedding[, k])Async return docs most similar to embedding vector.
Asynchronously return documents and scores above a threshold.
asimilarity_search_with_score
(query, *[, k])Asynchronously run similarity search with distance.
avector_search
(query[, k, filters])Returns the most similar indexed documents to the query text.
avector_search_with_score
(query[, k, filters])Return docs most similar to query.
delete
([ids])Delete by vector ID.
from_documents
(documents, embedding, **kwargs)Return VectorStore initialized from documents and embeddings.
from_embeddings
(text_embeddings, embedding)Create Azure Search vector store from text embeddings.
from_texts
(texts, embedding[, metadatas, ...])Create Azure Search vector store from a list of texts.
get_by_ids
(ids, /)Get documents by their IDs.
Return docs most similar to query with hybrid query and MMR reordering.
hybrid_search
(query[, k])Returns the most similar indexed documents to the query text.
hybrid_search_with_relevance_scores
(query[, ...])Return documents and scores above a threshold using hybrid search.
hybrid_search_with_score
(query[, k, filters])Return docs most similar to query with a hybrid query.
max_marginal_relevance_search
(query[, k, ...])Return docs selected using the maximal marginal relevance.
Return docs selected using the maximal marginal relevance.
Perform a search and return results that are reordered by MMR.
search
(query, search_type, **kwargs)Return docs most similar to query using a specified search type.
semantic_hybrid_search
(query[, k])Returns the most similar indexed documents to the query text.
semantic_hybrid_search_with_score
(query[, ...])Returns the most similar indexed documents to the query text.
Return docs most similar to query with a hybrid query.
similarity_search
(query[, k, search_type])Return documents most similar to the query using the specified search type.
similarity_search_by_vector
(embedding[, k])Return docs most similar to embedding vector.
Return documents and scores above a threshold using similarity search.
similarity_search_with_score
(query, *[, k])Run similarity search with distance.
vector_search
(query[, k, filters])Returns the most similar indexed documents to the query text.
vector_search_with_score
(query[, k, filters])Return docs most similar to query.
- __init__(
- azure_search_endpoint: str,
- azure_search_key: str | None,
- index_name: str,
- embedding_function: Callable | Embeddings,
- search_type: str = 'hybrid',
- semantic_configuration_name: str | None = None,
- fields: List[SearchField] | None = None,
- vector_search: VectorSearch | None = None,
- semantic_configurations: SemanticConfiguration | List[SemanticConfiguration] | None = None,
- scoring_profiles: List[ScoringProfile] | None = None,
- default_scoring_profile: str | None = None,
- cors_options: CorsOptions | None = None,
- *,
- vector_search_dimensions: int | None = None,
- additional_search_client_options: Dict[str, Any] | None = None,
- azure_ad_access_token: str | None = None,
- azure_credential: TokenCredential | None = None,
- azure_async_credential: AsyncTokenCredential | None = None,
- **kwargs: Any,
Initialize the AzureSearch vector store.
- Parameters:
azure_search_endpoint (str) – The endpoint URL for Azure Cognitive Search.
azure_search_key (str | None) – The API key for Azure Cognitive Search.
index_name (str) – The name of the index to use.
embedding_function (Callable | Embeddings) – The embedding function or object.
search_type (str) – The type of search to perform (default: “hybrid”).
semantic_configuration_name (str | None) – Optional semantic configuration name.
fields (List[SearchField] | None) – Optional list of search fields.
vector_search (VectorSearch | None) – Optional vector search configuration.
semantic_configurations (SemanticConfiguration | List[SemanticConfiguration] | None) – Optional semantic configurations.
scoring_profiles (List[ScoringProfile] | None) – Optional scoring profiles.
default_scoring_profile (str | None) – Optional default scoring profile.
cors_options (CorsOptions | None) – Optional CORS options.
vector_search_dimensions (int | None) – Optional vector search dimensions.
additional_search_client_options (Dict[str, Any] | None) – Additional options for the search client.
azure_ad_access_token (str | None) – Optional Azure AD access token.
azure_credential (TokenCredential | None) – Optional Azure credential.
azure_async_credential (AsyncTokenCredential | None) – Optional async Azure credential.
**kwargs (Any) – Additional keyword arguments.
- async aadd_documents(
- documents: list[Document],
- **kwargs: Any,
Async run more documents through the embeddings and add to the vectorstore.
- Parameters:
documents (list[Document]) – Documents to add to the vectorstore.
kwargs (Any) – Additional keyword arguments.
- Returns:
List of IDs of the added texts.
- Raises:
ValueError – If the number of IDs does not match the number of documents.
- Return type:
list[str]
- async aadd_embeddings(
- text_embeddings: Iterable[Tuple[str, List[float]]],
- metadatas: List[dict] | None = None,
- *,
- keys: List[str] | None = None,
Add embeddings to an existing index.
- Parameters:
text_embeddings (Iterable[Tuple[str, List[float]]])
metadatas (List[dict] | None)
keys (List[str] | None)
- Return type:
List[str]
- async aadd_texts(
- texts: Iterable[str],
- metadatas: List[dict] | None = None,
- *,
- keys: List[str] | None = None,
- **kwargs: Any,
Asynchronously add texts data to an existing index.
- Parameters:
texts (Iterable[str]) – Iterable of text strings to add.
metadatas (List[dict] | None) – Optional list of metadata dicts.
keys (List[str] | None) – Optional list of keys.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of IDs for the added texts.
- Return type:
List[str]
- add_documents(
- documents: list[Document],
- **kwargs: Any,
Add or update documents in the vectorstore.
- Parameters:
documents (list[Document]) – Documents to add to the vectorstore.
kwargs (Any) – Additional keyword arguments. if kwargs contains ids and documents contain ids, the ids in the kwargs will receive precedence.
- Returns:
List of IDs of the added texts.
- Raises:
ValueError – If the number of ids does not match the number of documents.
- Return type:
list[str]
- add_embeddings(
- text_embeddings: Iterable[Tuple[str, List[float]]],
- metadatas: List[dict] | None = None,
- *,
- keys: List[str] | None = None,
Add embeddings to an existing index.
- Parameters:
text_embeddings (Iterable[Tuple[str, List[float]]])
metadatas (List[dict] | None)
keys (List[str] | None)
- Return type:
List[str]
- add_texts(
- texts: Iterable[str],
- metadatas: List[dict] | None = None,
- *,
- keys: List[str] | None = None,
- **kwargs: Any,
Add texts data to an existing index.
- Parameters:
texts (Iterable[str])
metadatas (List[dict] | None)
keys (List[str] | None)
kwargs (Any)
- Return type:
List[str]
- async adelete(
- ids: List[str] | None = None,
- **kwargs: Any,
Asynchronously delete by vector ID.
- Parameters:
ids (List[str] | None) – List of ids to delete.
**kwargs (Any) – Additional keyword arguments.
- Returns:
True if deletion is successful, False otherwise.
- Return type:
bool
- async classmethod afrom_documents(
- documents: list[Document],
- embedding: Embeddings,
- **kwargs: Any,
Async return VectorStore initialized from documents and embeddings.
- Parameters:
documents (list[Document]) – List of Documents to add to the vectorstore.
embedding (Embeddings) – Embedding function to use.
kwargs (Any) – Additional keyword arguments.
- Returns:
VectorStore initialized from documents and embeddings.
- Return type:
- async classmethod afrom_embeddings(
- text_embeddings: Iterable[Tuple[str, List[float]]],
- embedding: Embeddings,
- metadatas: List[dict] | None = None,
- *,
- azure_search_endpoint: str = '',
- azure_search_key: str = '',
- index_name: str = 'langchain-index',
- fields: List[SearchField] | None = None,
- **kwargs: Any,
Asynchronously create Azure Search vector store from text embeddings.
- Parameters:
text_embeddings (Iterable[Tuple[str, List[float]]]) – Iterable of (text, embedding) tuples.
embedding (Embeddings) – Embeddings instance to use for future queries.
metadatas (List[dict] | None) – Optional list of metadata dicts for each text.
azure_search_endpoint (str) – Azure Search service endpoint.
azure_search_key (str) – Azure Search service API key.
index_name (str) – Name of the search index. Defaults to “langchain-index”.
fields (List[SearchField] | None) – List of search fields to use for the index.
**kwargs (Any) – Additional keyword arguments.
- Returns:
The created vector store instance.
- Return type:
- async classmethod afrom_texts(
- texts: List[str],
- embedding: Embeddings,
- metadatas: List[dict] | None = None,
- azure_search_endpoint: str = '',
- azure_search_key: str = '',
- azure_ad_access_token: str | None = None,
- index_name: str = 'langchain-index',
- fields: List[SearchField] | None = None,
- **kwargs: Any,
Asynchronously create Azure Search vector store from a list of texts.
- Parameters:
texts (List[str]) – List of texts to add to the vector store.
embedding (Embeddings) – Embeddings instance to use for encoding texts.
metadatas (List[dict] | None) – Optional list of metadata dicts for each text.
azure_search_endpoint (str) – Azure Search service endpoint.
azure_search_key (str) – Azure Search service API key.
azure_ad_access_token (str | None) – Azure AD access token for authentication.
index_name (str) – Name of the search index. Defaults to “langchain-index”.
fields (List[SearchField] | None) – List of search fields to use for the index.
**kwargs (Any) – Additional keyword arguments.
- Returns:
The created vector store instance.
- Return type:
- async aget_by_ids(
- ids: Sequence[str],
- /,
Async get documents by their IDs.
The returned documents are expected to have the ID field set to the ID of the document in the vector store.
Fewer documents may be returned than requested if some IDs are not found or if there are duplicated IDs.
Users should not assume that the order of the returned documents matches the order of the input IDs. Instead, users should rely on the ID field of the returned documents.
This method should NOT raise exceptions if no documents are found for some IDs.
- Parameters:
ids (Sequence[str]) – List of ids to retrieve.
- Returns:
List of Documents.
- Return type:
list[Document]
Added in version 0.2.11.
- async ahybrid_max_marginal_relevance_search_with_score(
- query: str,
- k: int = 4,
- fetch_k: int = 20,
- lambda_mult: float = 0.5,
- *,
- filters: str | None = None,
- **kwargs: Any,
Asynchronously return docs with hybrid query and MMR reordering.
- Parameters:
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Total results to select k from. Defaults to 20.
lambda_mult (float) – Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. Defaults to 0.5
filters (str | None) – Filtering expression. Defaults to None.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of Documents most similar to the query and score for each
- Return type:
List[Tuple[Document, float]]
- async ahybrid_search(
- query: str,
- k: int = 4,
- **kwargs: Any,
Returns the most similar indexed documents to the query text.
- Parameters:
query (str) – The query text for which to find similar documents.
k (int) – The number of documents to return. Default is 4.
**kwargs – Additional keyword arguments.
- Returns:
A list of documents that are most similar to the query text.
- Return type:
List[Document]
- async ahybrid_search_with_relevance_scores(
- query: str,
- k: int = 4,
- *,
- score_threshold: float | None = None,
- **kwargs: Any,
Asynchronously return documents and scores above a threshold.
- Parameters:
query (str) – The query string.
k (int) – Number of documents to return.
score_threshold (float | None) – Optional minimum score threshold.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of (Document, score) tuples.
- Return type:
List[Tuple[Document, float]]
- async ahybrid_search_with_score(
- query: str,
- k: int = 4,
- filters: str | None = None,
- **kwargs: Any,
Return docs most similar to query with a hybrid query.
- Parameters:
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filters (str | None) – Filtering expression. Defaults to None.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of Documents most similar to the query and score for each
- Return type:
List[Tuple[Document, float]]
- async amax_marginal_relevance_search(
- query: str,
- k: int = 4,
- fetch_k: int = 20,
- lambda_mult: float = 0.5,
- **kwargs: Any,
Async return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
- Parameters:
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm. Default is 20.
lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.
**kwargs (Any) – Arguments to pass to the search method.
- Returns:
List of Documents selected by maximal marginal relevance.
- Return type:
list[Document]
- async amax_marginal_relevance_search_by_vector(
- embedding: list[float],
- k: int = 4,
- fetch_k: int = 20,
- lambda_mult: float = 0.5,
- **kwargs: Any,
Async return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
- Parameters:
embedding (list[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm. Default is 20.
lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.
**kwargs (Any) – Arguments to pass to the search method.
- Returns:
List of Documents selected by maximal marginal relevance.
- Return type:
list[Document]
- async amax_marginal_relevance_search_with_score(
- query: str,
- k: int = 4,
- fetch_k: int = 20,
- lambda_mult: float = 0.5,
- *,
- filters: str | None = None,
- **kwargs: Any,
Perform a search and return results that are reordered by MMR.
- Parameters:
query (str) – Text to look up documents similar to.
k (int, optional) – How many results to give. Defaults to 4.
fetch_k (int, optional) – Total results to select k from. Defaults to 20.
lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5
filters (str, optional) – Filtering expression. Defaults to None.
**kwargs – Additional keyword arguments.
- Returns:
- List of Documents most similar
to the query and score for each
- Return type:
List[Tuple[Document, float]]
- as_retriever(
- **kwargs: Any,
Return AzureSearchVectorStoreRetriever initialized from this VectorStore.
- Parameters:
search_type (Optional[str]) – Overrides the type of search that the Retriever should perform. Defaults to self.search_type. Can be “similarity”, “hybrid”, or “semantic_hybrid”.
search_kwargs (Optional[Dict]) –
Keyword arguments to pass to the search function. Can include things like:
- score_threshold: Minimum relevance threshold
for similarity_score_threshold
fetch_k: Amount of documents to pass to MMR algorithm (Default: 20) lambda_mult: Diversity of results returned by MMR;
1 for minimum diversity and 0 for maximum. (Default: 0.5)
filter: Filter by document metadata
**kwargs (Any) – Additional keyword arguments.
- Returns:
Retriever class for VectorStore.
- Return type:
- async asearch(
- query: str,
- search_type: str,
- **kwargs: Any,
Async return docs most similar to query using a specified search type.
- Parameters:
query (str) – Input text.
search_type (str) – Type of search to perform. Can be “similarity”, “mmr”, or “similarity_score_threshold”.
**kwargs (Any) – Arguments to pass to the search method.
- Returns:
List of Documents most similar to the query.
- Raises:
ValueError – If search_type is not one of “similarity”, “mmr”, or “similarity_score_threshold”.
- Return type:
list[Document]
- async asemantic_hybrid_search(
- query: str,
- k: int = 4,
- **kwargs: Any,
Returns the most similar indexed documents to the query text.
- Parameters:
query (str) – The query text for which to find similar documents.
k (int) – The number of documents to return. Default is 4.
filters – Filtering expression.
**kwargs – Additional keyword arguments.
- Returns:
A list of documents that are most similar to the query text.
- Return type:
List[Document]
- async asemantic_hybrid_search_with_score(
- query: str,
- k: int = 4,
- score_type: Literal['score', 'reranker_score'] = 'score',
- *,
- score_threshold: float | None = None,
- **kwargs: Any,
Returns the most similar indexed documents to the query text.
- Parameters:
query (str) – The query text for which to find similar documents.
k (int) – The number of documents to return. Default is 4.
score_type (Literal['score', 'reranker_score']) – Must either be “score” or “reranker_score”. Defaulted to “score”.
score_threshold (float | None) – Minimum score threshold for results. Defaults to None.
**kwargs (Any) – Additional keyword arguments.
- Returns:
- A list of documents and their
corresponding scores.
- Return type:
List[Tuple[Document, float]]
- async asemantic_hybrid_search_with_score_and_rerank(
- query: str,
- k: int = 4,
- *,
- filters: str | None = None,
- **kwargs: Any,
Return docs most similar to query with a hybrid query.
- Parameters:
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filters (str | None) – Filtering expression.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of Documents most similar to the query and score for each
- Return type:
List[Tuple[Document, float, float]]
- async asimilarity_search(
- query: str,
- k: int = 4,
- *,
- search_type: str | None = None,
- **kwargs: Any,
Asynchronously return documents most similar to the query.
- Parameters:
query (str) – The query string.
k (int) – Number of documents to return.
search_type (str | None) – Optional search type override.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of similar documents.
- Return type:
List[Document]
- async asimilarity_search_by_vector(
- embedding: list[float],
- k: int = 4,
- **kwargs: Any,
Async return docs most similar to embedding vector.
- Parameters:
embedding (list[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
**kwargs (Any) – Arguments to pass to the search method.
- Returns:
List of Documents most similar to the query vector.
- Return type:
list[Document]
- async asimilarity_search_with_relevance_scores(
- query: str,
- k: int = 4,
- *,
- score_threshold: float | None = None,
- **kwargs: Any,
Asynchronously return documents and scores above a threshold.
- Parameters:
query (str) – The query string.
k (int) – Number of documents to return.
score_threshold (float | None) – Optional minimum score threshold.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of (Document, score) tuples.
- Return type:
List[Tuple[Document, float]]
- async asimilarity_search_with_score(
- query: str,
- *,
- k: int = 4,
- **kwargs: Any,
Asynchronously run similarity search with distance.
- Parameters:
query (str) – The query string.
k (int) – Number of documents to return.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of (Document, score) tuples.
- Return type:
List[Tuple[Document, float]]
- async avector_search(
- query: str,
- k: int = 4,
- *,
- filters: str | None = None,
- **kwargs: Any,
Returns the most similar indexed documents to the query text.
- Parameters:
query (str) – The query text for which to find similar documents.
k (int) – The number of documents to return. Default is 4.
filters (str | None) – Filtering expression. Defaults to None.
**kwargs (Any) – Additional keyword arguments.
- Returns:
A list of documents that are most similar to the query text.
- Return type:
List[Document]
- async avector_search_with_score(
- query: str,
- k: int = 4,
- filters: str | None = None,
- **kwargs: Any,
Return docs most similar to query.
- Parameters:
query (str) – Text to look up documents similar to.
k (int, optional) – Number of Documents to return. Defaults to 4.
filters (str, optional) – Filtering expression. Defaults to None.
**kwargs – Additional keyword arguments.
- Returns:
- List of Documents most similar
to the query and score for each
- Return type:
List[Tuple[Document, float]]
- delete(
- ids: List[str] | None = None,
- **kwargs: Any,
Delete by vector ID.
- Parameters:
ids (List[str] | None) – List of ids to delete.
**kwargs (Any) – Additional keyword arguments.
- Returns:
True if deletion is successful, False otherwise.
- Return type:
bool
- classmethod from_documents(
- documents: list[Document],
- embedding: Embeddings,
- **kwargs: Any,
Return VectorStore initialized from documents and embeddings.
- Parameters:
documents (list[Document]) – List of Documents to add to the vectorstore.
embedding (Embeddings) – Embedding function to use.
kwargs (Any) – Additional keyword arguments.
- Returns:
VectorStore initialized from documents and embeddings.
- Return type:
- classmethod from_embeddings(
- text_embeddings: Iterable[Tuple[str, List[float]]],
- embedding: Embeddings,
- metadatas: List[dict] | None = None,
- *,
- azure_search_endpoint: str = '',
- azure_search_key: str = '',
- index_name: str = 'langchain-index',
- fields: List[SearchField] | None = None,
- **kwargs: Any,
Create Azure Search vector store from text embeddings.
- Parameters:
text_embeddings (Iterable[Tuple[str, List[float]]]) – Iterable of (text, embedding) tuples.
embedding (Embeddings) – Embeddings instance to use for future queries.
metadatas (List[dict] | None) – Optional list of metadata dicts for each text.
azure_search_endpoint (str) – Azure Search service endpoint.
azure_search_key (str) – Azure Search service API key.
index_name (str) – Name of the search index. Defaults to “langchain-index”.
fields (List[SearchField] | None) – List of search fields to use for the index.
**kwargs (Any) – Additional keyword arguments.
- Returns:
The created vector store instance.
- Return type:
- classmethod from_texts(
- texts: List[str],
- embedding: Embeddings,
- metadatas: List[dict] | None = None,
- azure_search_endpoint: str = '',
- azure_search_key: str = '',
- azure_ad_access_token: str | None = None,
- index_name: str = 'langchain-index',
- fields: List[SearchField] | None = None,
- **kwargs: Any,
Create Azure Search vector store from a list of texts.
- Parameters:
texts (List[str]) – List of texts to add to the vector store.
embedding (Embeddings) – Embeddings instance to use for encoding texts.
metadatas (List[dict] | None) – Optional list of metadata dicts for each text.
azure_search_endpoint (str) – Azure Search service endpoint.
azure_search_key (str) – Azure Search service API key.
azure_ad_access_token (str | None) – Azure AD access token for authentication.
index_name (str) – Name of the search index. Defaults to “langchain-index”.
fields (List[SearchField] | None) – List of search fields to use for the index.
**kwargs (Any) – Additional keyword arguments.
- Returns:
The created vector store instance.
- Return type:
- get_by_ids(
- ids: Sequence[str],
- /,
Get documents by their IDs.
The returned documents are expected to have the ID field set to the ID of the document in the vector store.
Fewer documents may be returned than requested if some IDs are not found or if there are duplicated IDs.
Users should not assume that the order of the returned documents matches the order of the input IDs. Instead, users should rely on the ID field of the returned documents.
This method should NOT raise exceptions if no documents are found for some IDs.
- Parameters:
ids (Sequence[str]) – List of ids to retrieve.
- Returns:
List of Documents.
- Return type:
list[Document]
Added in version 0.2.11.
- hybrid_max_marginal_relevance_search_with_score(
- query: str,
- k: int = 4,
- fetch_k: int = 20,
- lambda_mult: float = 0.5,
- *,
- filters: str | None = None,
- **kwargs: Any,
Return docs most similar to query with hybrid query and MMR reordering.
- Parameters:
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Total results to select k from. Defaults to 20.
lambda_mult (float) – Diversity of results returned by MMR; 1 for minimum diversity and 0 for maximum. Defaults to 0.5
filters (str | None) – Filtering expression. Defaults to None.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of Documents most similar to the query and score for each
- Return type:
List[Tuple[Document, float]]
- hybrid_search(
- query: str,
- k: int = 4,
- **kwargs: Any,
Returns the most similar indexed documents to the query text.
- Parameters:
query (str) – The query text for which to find similar documents.
k (int) – The number of documents to return. Default is 4.
**kwargs – Additional keyword arguments.
- Returns:
A list of documents that are most similar to the query text.
- Return type:
List[Document]
- hybrid_search_with_relevance_scores(
- query: str,
- k: int = 4,
- *,
- score_threshold: float | None = None,
- **kwargs: Any,
Return documents and scores above a threshold using hybrid search.
- Parameters:
query (str) – The query string.
k (int) – Number of documents to return.
score_threshold (float | None) – Optional minimum score threshold.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of (Document, score) tuples.
- Return type:
List[Tuple[Document, float]]
- hybrid_search_with_score(
- query: str,
- k: int = 4,
- filters: str | None = None,
- **kwargs: Any,
Return docs most similar to query with a hybrid query.
- Parameters:
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filters (str | None) – Filtering expression. Defaults to None.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of Documents most similar to the query and score for each
- Return type:
List[Tuple[Document, float]]
- max_marginal_relevance_search(
- query: str,
- k: int = 4,
- fetch_k: int = 20,
- lambda_mult: float = 0.5,
- **kwargs: Any,
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
- Parameters:
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm. Default is 20.
lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.
**kwargs (Any) – Arguments to pass to the search method.
- Returns:
List of Documents selected by maximal marginal relevance.
- Return type:
list[Document]
- max_marginal_relevance_search_by_vector(
- embedding: list[float],
- k: int = 4,
- fetch_k: int = 20,
- lambda_mult: float = 0.5,
- **kwargs: Any,
Return docs selected using the maximal marginal relevance.
Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.
- Parameters:
embedding (list[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
fetch_k (int) – Number of Documents to fetch to pass to MMR algorithm. Default is 20.
lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5.
**kwargs (Any) – Arguments to pass to the search method.
- Returns:
List of Documents selected by maximal marginal relevance.
- Return type:
list[Document]
- max_marginal_relevance_search_with_score(
- query: str,
- k: int = 4,
- fetch_k: int = 20,
- lambda_mult: float = 0.5,
- *,
- filters: str | None = None,
- **kwargs: Any,
Perform a search and return results that are reordered by MMR.
- Parameters:
query (str) – Text to look up documents similar to.
k (int, optional) – How many results to give. Defaults to 4.
fetch_k (int, optional) – Total results to select k from. Defaults to 20.
lambda_mult (float) – Number between 0 and 1 that determines the degree of diversity among the results with 0 corresponding to maximum diversity and 1 to minimum diversity. Defaults to 0.5
filters (str, optional) – Filtering expression. Defaults to None.
**kwargs – Additional keyword arguments.
- Returns:
- List of Documents most similar
to the query and score for each
- Return type:
List[Tuple[Document, float]]
- search(
- query: str,
- search_type: str,
- **kwargs: Any,
Return docs most similar to query using a specified search type.
- Parameters:
query (str) – Input text
search_type (str) – Type of search to perform. Can be “similarity”, “mmr”, or “similarity_score_threshold”.
**kwargs (Any) – Arguments to pass to the search method.
- Returns:
List of Documents most similar to the query.
- Raises:
ValueError – If search_type is not one of “similarity”, “mmr”, or “similarity_score_threshold”.
- Return type:
list[Document]
- semantic_hybrid_search(
- query: str,
- k: int = 4,
- **kwargs: Any,
Returns the most similar indexed documents to the query text.
- Parameters:
query (str) – The query text for which to find similar documents.
k (int) – The number of documents to return. Default is 4.
filters – Filtering expression.
**kwargs – Additional keyword arguments.
- Returns:
A list of documents that are most similar to the query text.
- Return type:
List[Document]
- semantic_hybrid_search_with_score(
- query: str,
- k: int = 4,
- score_type: Literal['score', 'reranker_score'] = 'score',
- *,
- score_threshold: float | None = None,
- **kwargs: Any,
Returns the most similar indexed documents to the query text.
- Parameters:
query (str) – The query text for which to find similar documents.
k (int) – The number of documents to return. Default is 4.
score_type (Literal['score', 'reranker_score']) – Must either be “score” or “reranker_score”. Defaulted to “score”.
score_threshold (float | None) – Minimum score threshold for results. Defaults to None.
**kwargs (Any) – Additional keyword arguments.
- Returns:
- A list of documents and their
corresponding scores.
- Return type:
List[Tuple[Document, float]]
- semantic_hybrid_search_with_score_and_rerank(
- query: str,
- k: int = 4,
- *,
- filters: str | None = None,
- **kwargs: Any,
Return docs most similar to query with a hybrid query.
- Parameters:
query (str) – Text to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
filters (str | None) – Filtering expression.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of Documents most similar to the query and score for each
- Return type:
List[Tuple[Document, float, float]]
- similarity_search(
- query: str,
- k: int = 4,
- *,
- search_type: str | None = None,
- **kwargs: Any,
Return documents most similar to the query using the specified search type.
- Parameters:
query (str) – The query string.
k (int) – Number of documents to return.
search_type (str | None) – Optional search type override.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of similar documents.
- Return type:
List[Document]
- similarity_search_by_vector(
- embedding: list[float],
- k: int = 4,
- **kwargs: Any,
Return docs most similar to embedding vector.
- Parameters:
embedding (list[float]) – Embedding to look up documents similar to.
k (int) – Number of Documents to return. Defaults to 4.
**kwargs (Any) – Arguments to pass to the search method.
- Returns:
List of Documents most similar to the query vector.
- Return type:
list[Document]
- similarity_search_with_relevance_scores(
- query: str,
- k: int = 4,
- *,
- score_threshold: float | None = None,
- **kwargs: Any,
Return documents and scores above a threshold using similarity search.
- Parameters:
query (str) – The query string.
k (int) – Number of documents to return.
score_threshold (float | None) – Optional minimum score threshold.
**kwargs (Any) – Additional keyword arguments.
- Returns:
List of (Document, score) tuples.
- Return type:
List[Tuple[Document, float]]
- similarity_search_with_score(
- query: str,
- *,
- k: int = 4,
- **kwargs: Any,
Run similarity search with distance.
- Parameters:
query (str)
k (int)
kwargs (Any)
- Return type:
List[Tuple[Document, float]]
- vector_search(
- query: str,
- k: int = 4,
- *,
- filters: str | None = None,
- **kwargs: Any,
Returns the most similar indexed documents to the query text.
- Parameters:
query (str) – The query text for which to find similar documents.
k (int) – The number of documents to return. Default is 4.
filters (str | None) – Filtering expression. Defaults to None.
**kwargs (Any) – Additional keyword arguments.
- Returns:
A list of documents that are most similar to the query text.
- Return type:
List[Document]
- vector_search_with_score(
- query: str,
- k: int = 4,
- filters: str | None = None,
- **kwargs: Any,
Return docs most similar to query.
- Parameters:
query (str) – Text to look up documents similar to.
k (int, optional) – Number of Documents to return. Defaults to 4.
filters (str, optional) – Filtering expression. Defaults to None.
**kwargs – Additional keyword arguments.
- Returns:
- List of Documents most similar
to the query and score for each
- Return type:
List[Tuple[Document, float]]
Examples using AzureSearch