id
stringlengths
14
16
text
stringlengths
4
1.28k
source
stringlengths
54
121
d13c8ecaa8b9-1
def __init__( self, user_id: Optional[str] = None, app_id: Optional[str] = None, pat: Optional[str] = None, number_of_docs: Optional[int] = None, api_base: Optional[str] = None, ) -> None: """Initialize with Clarifai client. Args: user_id (...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-2
Raises: ValueError: If user ID, app ID or personal access token is not provided. """ try: from clarifai.auth.helper import DEFAULT_BASE, ClarifaiAuthHelper from clarifai.client import create_stub except ImportError: raise ValueError( ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-3
raise ValueError( "Could not find CLARIFAI_USER_ID, CLARIFAI_APP_ID or\ CLARIFAI_PAT in your environment. " "Please set those env variables with a valid user ID, \ app ID and personal access token \ from https://clarifai.com/settings/securi...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-4
"""Post text to Clarifai and return the ID of the input. Args: text (str): Text to post. metadata (dict): Metadata to post. Returns: str: ID of the input. """ try: from clarifai_grpc.grpc.api import resources_pb2, service_pb2 fr...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-5
user_app_id=self._userDataObject, inputs=[ resources_pb2.Input( data=resources_pb2.Data( text=resources_pb2.Text(raw=text), metadata=input_metadata, ) ) ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-6
) -> List[str]: """Add texts to the Clarifai vectorstore. This will push the text to a Clarifai application. Application use base workflow that create and store embedding for each text. Make sure you are using a base workflow that is compatible with text (such as Language Underst...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-7
metadatas ), "Number of texts and metadatas should be the same." input_ids = [] for idx, text in enumerate(texts): try: metadata = metadatas[idx] if metadatas else {} input_id = self._post_text_input(text, metadata) input_ids.append...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-8
"""Run similarity search with score using Clarifai. Args: query (str): Query text to search for. k (int): Number of results to return. Defaults to 4. filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None. Returns: List[Documen...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-9
# Get number of docs to return if self._number_of_docs is not None: k = self._number_of_docs post_annotations_searches_response = self._stub.PostAnnotationsSearches( service_pb2.PostAnnotationsSearchesRequest( user_app_id=self._userDataObject, sear...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-10
raise Exception( "Post searches failed, status: " + post_annotations_searches_response.status.description ) # Retrieve hits hits = post_annotations_searches_response.hits docs_and_scores = [] # Iterate over hits and retrieve metadata and text ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-11
) return docs_and_scores [docs] def similarity_search( self, query: str, k: int = 4, **kwargs: Any, ) -> List[Document]: """Run similarity search using Clarifai. Args: query: Text to look up documents similar to. k: Number of Documen...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-12
user_id: Optional[str] = None, app_id: Optional[str] = None, pat: Optional[str] = None, number_of_docs: Optional[int] = None, api_base: Optional[str] = None, **kwargs: Any, ) -> Clarifai: """Create a Clarifai vectorstore from a list of texts. Args: ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-13
Defaults to None. Returns: Clarifai: Clarifai vectorstore. """ clarifai_vector_db = cls( user_id=user_id, app_id=app_id, pat=pat, number_of_docs=number_of_docs, api_base=api_base, ) clarifai_vector_db.add_tex...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-14
**kwargs: Any, ) -> Clarifai: """Create a Clarifai vectorstore from a list of documents. Args: user_id (str): User ID. app_id (str): App ID. documents (List[Document]): List of documents to add. pat (Optional[str]): Personal access token. Defaults to N...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
d13c8ecaa8b9-15
texts=texts, pat=pat, number_of_docs=number_of_docs, api_base=api_base, metadatas=metadatas, )
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/clarifai.html
f3a79db35451-0
Source code for langchain.vectorstores.chroma """Wrapper around ChromaDB embeddings platform.""" from __future__ import annotations import logging import uuid from typing import TYPE_CHECKING, Any, Dict, Iterable, List, Optional, Tuple, Type import numpy as np from langchain.docstore.document import Document from langc...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-1
def _results_to_docs_and_scores(results: Any) -> List[Tuple[Document, float]]: return [ # TODO: Chroma can do batch querying, # we shouldn't hard code to the 1st result (Document(page_content=result[0], metadata=result[1] or {}), result[2]) for result in zip( results["doc...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-2
embeddings = OpenAIEmbeddings() vectorstore = Chroma("langchain_store", embeddings) """ _LANGCHAIN_DEFAULT_COLLECTION_NAME = "langchain" def __init__( self, collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME, embedding_function: Optional[Embeddings] = None, ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-3
) if client is not None: self._client = client else: if client_settings: self._client_settings = client_settings else: self._client_settings = chromadb.config.Settings() if persist_directory is not None: ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-4
def __query_collection( self, query_texts: Optional[List[str]] = None, query_embeddings: Optional[List[List[float]]] = None, n_results: int = 4, where: Optional[Dict[str, str]] = None, **kwargs: Any, ) -> List[Document]: """Query the chroma collection.""" ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-5
self, texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, **kwargs: Any, ) -> List[str]: """Run more texts through the embeddings and add to the vectorstore. Args: texts (Iterable[str]): Texts to add to the vector...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-6
embeddings = self._embedding_function.embed_documents(list(texts)) self._collection.upsert( metadatas=metadatas, embeddings=embeddings, documents=texts, ids=ids ) return ids [docs] def similarity_search( self, query: str, k: int = DEFAULT_K, filter:...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-7
""" docs_and_scores = self.similarity_search_with_score(query, k, filter=filter) return [doc for doc, _ in docs_and_scores] [docs] def similarity_search_by_vector( self, embedding: List[float], k: int = DEFAULT_K, filter: Optional[Dict[str, str]] = None, **kwar...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-8
results = self.__query_collection( query_embeddings=embedding, n_results=k, where=filter ) return _results_to_docs(results) [docs] def similarity_search_with_score( self, query: str, k: int = DEFAULT_K, filter: Optional[Dict[str, str]] = None, **kwa...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-9
Lower score represents more similarity. """ if self._embedding_function is None: results = self.__query_collection( query_texts=[query], n_results=k, where=filter ) else: query_embedding = self._embedding_function.embed_query(query) ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-10
embedding: List[float], k: int = DEFAULT_K, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, str]] = None, **kwargs: Any, ) -> List[Document]: """Return docs selected using the maximal marginal relevance. Maximal marginal relevance optim...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-11
Defaults to 0.5. filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None. Returns: List of Documents selected by maximal marginal relevance. """ results = self.__query_collection( query_embeddings=embedding, n_results=fetch_k, ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-12
self, query: str, k: int = DEFAULT_K, fetch_k: int = 20, lambda_mult: float = 0.5, filter: Optional[Dict[str, str]] = None, **kwargs: Any, ) -> List[Document]: """Return docs selected using the maximal marginal relevance. Maximal marginal relevance opt...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-13
Defaults to 0.5. filter (Optional[Dict[str, str]]): Filter by metadata. Defaults to None. Returns: List of Documents selected by maximal marginal relevance. """ if self._embedding_function is None: raise ValueError( "For MMR search, you must sp...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-14
where: Optional[Where] = None, limit: Optional[int] = None, offset: Optional[int] = None, where_document: Optional[WhereDocument] = None, include: Optional[List[str]] = None, ) -> Dict[str, Any]: """Gets the collection. Args: ids: The ids of the embeddings...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-15
include: A list of what to include in the results. Can contain `"embeddings"`, `"metadatas"`, `"documents"`. Ids are always included. Defaults to `["metadatas", "documents"]`. Optional. """ kwargs = { "ids": ids, "whe...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-16
raise ValueError( "You must specify a persist_directory on" "creation to persist the collection." ) self._client.persist() [docs] def update_document(self, document_id: str, document: Document) -> None: """Update a document in the collection. Args: ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-17
) [docs] @classmethod def from_texts( cls: Type[Chroma], texts: List[str], embedding: Optional[Embeddings] = None, metadatas: Optional[List[dict]] = None, ids: Optional[List[str]] = None, collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME, persist_di...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-18
collection_name (str): Name of the collection to create. persist_directory (Optional[str]): Directory to persist the collection. embedding (Optional[Embeddings]): Embedding function. Defaults to None. metadatas (Optional[List[dict]]): List of metadatas. Defaults to None. ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-19
return chroma_collection [docs] @classmethod def from_documents( cls: Type[Chroma], documents: List[Document], embedding: Optional[Embeddings] = None, ids: Optional[List[str]] = None, collection_name: str = _LANGCHAIN_DEFAULT_COLLECTION_NAME, persist_directory: Opt...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-20
persist_directory (Optional[str]): Directory to persist the collection. ids (Optional[List[str]]): List of document IDs. Defaults to None. documents (List[Document]): List of documents to add to the vectorstore. embedding (Optional[Embeddings]): Embedding function. Defaults to None. ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
f3a79db35451-21
client=client, ) [docs] def delete(self, ids: List[str]) -> None: """Delete by vector IDs. Args: ids: List of ids to delete. """ self._collection.delete(ids=ids)
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/chroma.html
bd06d29fdf84-0
Source code for langchain.vectorstores.qdrant """Wrapper around Qdrant vector database.""" from __future__ import annotations import uuid import warnings from itertools import islice from operator import itemgetter from typing import ( TYPE_CHECKING, Any, Callable, Dict, Iterable, List, Opti...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-1
MetadataFilter = Union[DictFilter, common_types.Filter] [docs]class Qdrant(VectorStore): """Wrapper around Qdrant vector database. To use you should have the ``qdrant-client`` package installed. Example: .. code-block:: python from qdrant_client import QdrantClient from langc...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-2
embedding_function: Optional[Callable] = None, # deprecated ): """Initialize with necessary components.""" try: import qdrant_client except ImportError: raise ValueError( "Could not import qdrant-client python package. " "Please instal...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-3
raise ValueError( "Both `embeddings` and `embedding_function` are passed. " "Use `embeddings` only." ) self.embeddings = embeddings self._embeddings_function = embedding_function self.client: qdrant_client.QdrantClient = client self.collection_...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-4
) self._embeddings_function = embeddings self.embeddings = None [docs] def add_texts( self, texts: Iterable[str], metadatas: Optional[List[dict]] = None, ids: Optional[Sequence[str]] = None, batch_size: int = 64, **kwargs: Any, ) -> List[str...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-5
Default: 64 Returns: List of ids from adding the texts into the vectorstore. """ from qdrant_client.http import models as rest added_ids = [] texts_iterator = iter(texts) metadatas_iterator = iter(metadatas or []) ids_iterator = iter(ids or [uuid.uuid4...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-6
vectors=self._embed_texts(batch_texts), payloads=self._build_payloads( batch_texts, batch_metadatas, self.content_payload_key, self.metadata_payload_key, ), ), ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-7
k: Number of Documents to return. Defaults to 4. filter: Filter by metadata. Defaults to None. search_params: Additional search params offset: Offset of the first result to return. May be used to paginate results. Note: large offset val...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-8
queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas - 'quorum' - query the majority of replicas, return values present in all of them - 'all' - query all repl...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-9
k: int = 4, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, offset: int = 0, score_threshold: Optional[float] = None, consistency: Optional[common_types.ReadConsistency] = None, **kwargs: Any, ) -> List[Tuple[Documen...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-10
score_threshold: Define a minimal score threshold for the result. If defined, less similar results will not be returned. Score of the returned result might be higher or smaller than the threshold depending on the Distance function used. E.g...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-11
distance in float for each. Lower score represents more similarity. """ return self.similarity_search_with_score_by_vector( self._embed_query(query), k, filter=filter, search_params=search_params, offset=offset, score_th...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-12
) -> List[Document]: """Return docs most similar to embedding vector. Args: embedding: Embedding vector to look up documents similar to. k: Number of Documents to return. Defaults to 4. filter: Filter by metadata. Defaults to None. search_params: Additiona...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-13
queried before returning the result. Values: - int - number of replicas to query, values should present in all queried replicas - 'majority' - query all replicas, but return values present in the majority of replicas ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-14
[docs] def similarity_search_with_score_by_vector( self, embedding: List[float], k: int = 4, filter: Optional[MetadataFilter] = None, search_params: Optional[common_types.SearchParams] = None, offset: int = 0, score_threshold: Optional[float] = None, co...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-15
Offset of the first result to return. May be used to paginate results. Note: large offset values may cause performance issues. score_threshold: Define a minimal score threshold for the result. If defined, less similar results will not be return...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-16
all of them - 'all' - query all replicas, and return values present in all replicas Returns: List of documents most similar to the query text and cosine distance in float for each. Lower score represents more similarity. """ if filter is not No...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-17
search_params=search_params, limit=k, offset=offset, with_payload=True, with_vectors=False, # Langchain does not expect vectors to be returned score_threshold=score_threshold, consistency=consistency, **kwargs, ) return...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-18
Args: query: input text k: Number of Documents to return. Defaults to 4. **kwargs: kwargs to be passed to similarity search. Should include: score_threshold: Optional, a floating point value between 0 to 1 to filter the resulting set of retrieved d...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-19
among selected documents. Args: query: Text to look up documents similar to. k: Number of Documents to return. Defaults to 4. fetch_k: Number of Documents to fetch to pass to MMR algorithm. Defaults to 20. lambda_mult: Number between 0 and 1 t...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-20
mmr_selected = maximal_marginal_relevance( np.array(embedding), embeddings, k=k, lambda_mult=lambda_mult ) return [ self._document_from_scored_point( results[i], self.content_payload_key, self.metadata_payload_key ) for i in mmr_selected ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-21
prefer_grpc: bool = False, https: Optional[bool] = None, api_key: Optional[str] = None, prefix: Optional[str] = None, timeout: Optional[float] = None, host: Optional[str] = None, path: Optional[str] = None, collection_name: Optional[str] = None, distance_f...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-22
optimizers_config: Optional[common_types.OptimizersConfigDiff] = None, wal_config: Optional[common_types.WalConfigDiff] = None, quantization_config: Optional[common_types.QuantizationConfig] = None, init_from: Optional[common_types.InitFrom] = None, **kwargs: Any, ) -> Qdrant: ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-23
uuid-like strings. location: If `:memory:` - use in-memory Qdrant instance. If `str` - use it as a `url` parameter. If `None` - fallback to relying on `host` and `port` parameters. url: either host or str of "Optional[scheme], host, Optional[port],...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-24
prefix: If not None - add prefix to the REST URL path. Example: service/v1 will result in http://localhost:6333/service/v1/{qdrant-endpoint} for REST API. Default: None timeout: Timeout for REST and gRPC API requests. ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-25
Default: "Cosine" content_payload_key: A payload key used to store the content of the document. Default: "page_content" metadata_payload_key: A payload key used to store the metadata of the document. Default: "metadata" ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-26
it successful. Increasing this number will make the collection more resilient to inconsistencies, but will also make it fail if not enough replicas are available. Does not have any performance impact. Have effect only in distributed mode. on_di...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-27
**kwargs: Additional arguments passed directly into REST client initialization This is a user-friendly interface that: 1. Creates embeddings, one for each text 2. Initializes the Qdrant database as an in-memory docstore by default (and overridable to a remote docstore)...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-28
"Please install it with `pip install qdrant-client`." ) from qdrant_client.http import models as rest # Just do a single quick embedding to get vector size partial_embeddings = embedding.embed_documents(texts[:1]) vector_size = len(partial_embeddings[0]) collection_na...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-29
collection_name=collection_name, vectors_config=rest.VectorParams( size=vector_size, distance=rest.Distance[distance_func], ), shard_number=shard_number, replication_factor=replication_factor, write_consistency_factor=write_cons...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-30
# Take the corresponding metadata and id for each text in a batch batch_metadatas = list(islice(metadatas_iterator, batch_size)) or None batch_ids = list(islice(ids_iterator, batch_size)) # Generate the embeddings for all the texts in a batch batch_embeddings = embedding....
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-31
) @classmethod def _build_payloads( cls, texts: Iterable[str], metadatas: Optional[List[dict]], content_payload_key: str, metadata_payload_key: str, ) -> List[dict]: payloads = [] for i, text in enumerate(texts): if text is None: ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-32
cls, scored_point: Any, content_payload_key: str, metadata_payload_key: str, ) -> Document: return Document( page_content=scored_point.payload.get(content_payload_key), metadata=scored_point.payload.get(metadata_payload_key) or {}, ) def _build_con...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-33
else: out.extend(self._build_condition(f"{key}", _value)) else: out.append( rest.FieldCondition( key=f"{self.metadata_payload_key}.{key}", match=rest.MatchValue(value=value), ) ) return ou...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-34
Args: query: Query text. Returns: List of floats representing the query embedding. """ if self.embeddings is not None: embedding = self.embeddings.embed_query(query) else: if self._embeddings_function is not None: embedding ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
bd06d29fdf84-35
if self.embeddings is not None: embeddings = self.embeddings.embed_documents(list(texts)) if hasattr(embeddings, "tolist"): embeddings = embeddings.tolist() elif self._embeddings_function is not None: embeddings = [] for text in texts: ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/qdrant.html
c8f38cddf6f5-0
Source code for langchain.vectorstores.azuresearch """Wrapper around Azure Cognitive Search.""" from __future__ import annotations import base64 import json import logging import uuid from typing import ( TYPE_CHECKING, Any, Callable, Dict, Iterable, List, Optional, Tuple, Type, ) im...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-1
FIELDS_ID = get_from_env( key="AZURESEARCH_FIELDS_ID", env_key="AZURESEARCH_FIELDS_ID", default="id" ) FIELDS_CONTENT = get_from_env( key="AZURESEARCH_FIELDS_CONTENT", env_key="AZURESEARCH_FIELDS_CONTENT", default="content", ) FIELDS_CONTENT_VECTOR = get_from_env( key="AZURESEARCH_FIELDS_CONTENT_VEC...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-2
) -> SearchClient: from azure.core.credentials import AzureKeyCredential from azure.core.exceptions import ResourceNotFoundError from azure.identity import DefaultAzureCredential from azure.search.documents import SearchClient from azure.search.documents.indexes import SearchIndexClient from azu...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-3
index_client.get_index(name=index_name) except ResourceNotFoundError: # Fields configuration fields = [ SimpleField( name=FIELDS_ID, type=SearchFieldDataType.String, key=True, filterable=True, ), Sear...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-4
] # Vector search configuration vector_search = VectorSearch( algorithm_configurations=[ VectorSearchAlgorithmConfiguration( name="default", kind="hnsw", hnsw_parameters={ "m": 4, ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-5
] ) ) # Create the search index with the semantic settings and vector search index = SearchIndex( name=index_name, fields=fields, vector_search=vector_search, semantic_settings=semantic_settings, ) index_client.create_in...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-6
"""Initialize with necessary components.""" # Initialize base class self.embedding_function = embedding_function self.client = _get_search_client( azure_search_endpoint, azure_search_key, index_name, embedding_function, semantic_configu...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-7
# Use provided key otherwise use default key key = keys[i] if keys else str(uuid.uuid4()) # Encoding key for Azure Search valid characters key = base64.urlsafe_b64encode(bytes(key, "utf-8")).decode("ascii") metadata = metadatas[i] if metadatas else {} # Add da...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-8
# Check if all documents were successfully uploaded if not all([r.succeeded for r in response]): raise Exception(response) # Reset data data = [] # Considering case where data is an exact multiple of batch-size entries if len(data) == 0...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-9
if search_type == "similarity": docs = self.vector_search(query, k=k, **kwargs) elif search_type == "hybrid": docs = self.hybrid_search(query, k=k, **kwargs) elif search_type == "semantic_hybrid": docs = self.semantic_hybrid_search(query, k=k, **kwargs) else: ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-10
Returns: List[Document]: A list of documents that are most similar to the query text. """ docs_and_scores = self.vector_search_with_score( query, k=k, filters=kwargs.get("filters", None) ) return [doc for doc, _ in docs_and_scores] [docs] def vector_search_with...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-11
results = self.client.search( search_text="", vector=Vector( value=np.array( self.embedding_function(query), dtype=np.float32 ).tolist(), k=k, fields=FIELDS_CONTENT_VECTOR, ), select=[f"{F...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-12
Args: query (str): The query text for which to find similar documents. k (int): The number of documents to return. Default is 4. Returns: List[Document]: A list of documents that are most similar to the query text. """ docs_and_scores = self.hybrid_search_with...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-13
k: Number of Documents to return. Defaults to 4. Returns: List of Documents most similar to the query and score for each """ from azure.search.documents.models import Vector results = self.client.search( search_text=query, vector=Vector( ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-14
] return docs [docs] def semantic_hybrid_search( self, query: str, k: int = 4, **kwargs: Any ) -> List[Document]: """ Returns the most similar indexed documents to the query text. Args: query (str): The query text for which to find similar documents. ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-15
self, query: str, k: int = 4, filters: Optional[str] = None ) -> List[Tuple[Document, float]]: """Return docs most similar to query with an hybrid query. Args: query: Text to look up documents similar to. k: Number of Documents to return. Defaults to 4. Returns: ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-16
filter=filters, query_type="semantic", query_language=self.semantic_query_language, semantic_configuration_name=self.semantic_configuration_name, query_caption="extractive", query_answer="extractive", top=k, ) # Get Semantic Answers...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-17
"highlights": result.get("@search.captions", [{}])[ 0 ].highlights, } if result.get("@search.captions") else {}, "answers": semantic_answers...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-18
) -> AzureSearch: # Creating a new Azure Search instance azure_search = cls( azure_search_endpoint, azure_search_key, index_name, embedding.embed_query, ) azure_search.add_texts(texts, metadatas, **kwargs) return azure_search class ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-19
search_type = values["search_type"] if search_type not in ("similarity", "hybrid", "semantic_hybrid"): raise ValueError(f"search_type of {search_type} not allowed.") return values def get_relevant_documents(self, query: str) -> List[Document]: if self.search_type == "simi...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
c8f38cddf6f5-20
raise NotImplementedError( "AzureSearchVectorStoreRetriever does not support async" )
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/azuresearch.html
825682b7a014-0
Source code for langchain.vectorstores.cassandra """Wrapper around Cassandra vector-store capabilities, based on cassIO.""" from __future__ import annotations import hashlib import typing from typing import Any, Iterable, List, Optional, Tuple, Type, TypeVar import numpy as np if typing.TYPE_CHECKING: from cassandr...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/cassandra.html
825682b7a014-1
[docs]class Cassandra(VectorStore): """Wrapper around Cassandra embeddings platform. There is no notion of a default table name, since each embedding function implies its own vector dimension, which is part of the schema. Example: .. code-block:: python from langchain.vectorstore...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/cassandra.html
825682b7a014-2
def __init__( self, embedding: Embeddings, session: Session, keyspace: str, table_name: str, ttl_seconds: int | None = CASSANDRA_VECTORSTORE_DEFAULT_TTL_SECONDS, ) -> None: try: from cassio.vector import VectorTable except (ImportError, Mod...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/cassandra.html
825682b7a014-3
keyspace=keyspace, table=table_name, embedding_dimension=self._getEmbeddingDimension(), auto_id=False, # the `add_texts` contract admits user-provided ids ) [docs] def delete_collection(self) -> None: """ Just an alias for `clear` (to better align ...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/cassandra.html
825682b7a014-4
**kwargs: Any, ) -> List[str]: """Run more texts through the embeddings and add to the vectorstore. Args: texts (Iterable[str]): Texts to add to the vectorstore. metadatas (Optional[List[dict]], optional): Optional list of metadatas. ids (Optional[List[str]], opti...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/cassandra.html
825682b7a014-5
if metadatas is None: metadatas = [{} for _ in _texts] # ttl_seconds = kwargs.get("ttl_seconds", self.ttl_seconds) # embedding_vectors = self.embedding.embed_documents(_texts) for text, embedding_vector, text_id, metadata in zip( _texts, embedding_vectors,...
https://api.python.langchain.com/en/latest/_modules/langchain/vectorstores/cassandra.html