[docs]classUpstashVectorStore(VectorStore):"""Upstash Vector vector store To use, the ``upstash-vector`` python package must be installed. Also an Upstash Vector index is required. First create a new Upstash Vector index and copy the `index_url` and `index_token` variables. Then either pass them through the constructor or set the environment variables `UPSTASH_VECTOR_REST_URL` and `UPSTASH_VECTOR_REST_TOKEN`. Example: .. code-block:: python from langchain_openai import OpenAIEmbeddings from langchain_community.vectorstores import UpstashVectorStore embeddings = OpenAIEmbeddings(model="text-embedding-3-large") vectorstore = UpstashVectorStore( embedding=embeddings, index_url="...", index_token="..." ) # or import os os.environ["UPSTASH_VECTOR_REST_URL"] = "..." os.environ["UPSTASH_VECTOR_REST_TOKEN"] = "..." vectorstore = UpstashVectorStore( embedding=embeddings ) """
[docs]def__init__(self,text_key:str="text",index:Optional[Index]=None,async_index:Optional[AsyncIndex]=None,index_url:Optional[str]=None,index_token:Optional[str]=None,embedding:Optional[Union[Embeddings,bool]]=None,*,namespace:str="",):""" Constructor for UpstashVectorStore. If index or index_url and index_token are not provided, the constructor will attempt to create an index using the environment variables `UPSTASH_VECTOR_REST_URL`and `UPSTASH_VECTOR_REST_TOKEN`. Args: text_key: Key to store the text in metadata. index: UpstashVector Index object. async_index: UpstashVector AsyncIndex object, provide only if async functions are needed index_url: URL of the UpstashVector index. index_token: Token of the UpstashVector index. embedding: Embeddings object or a boolean. When false, no embedding is applied. If true, Upstash embeddings are used. When Upstash embeddings are used, text is sent directly to Upstash and embedding is applied there instead of embedding in Langchain. namespace: Namespace to use from the index. Example: .. code-block:: python from langchain_community.vectorstores.upstash import UpstashVectorStore from langchain_community.embeddings.openai import OpenAIEmbeddings embeddings = OpenAIEmbeddings() vectorstore = UpstashVectorStore( embedding=embeddings, index_url="...", index_token="...", namespace="..." ) # With an existing index from upstash_vector import Index index = Index(url="...", token="...") vectorstore = UpstashVectorStore( embedding=embeddings, index=index, namespace="..." ) """try:fromupstash_vectorimportAsyncIndex,IndexexceptImportError:raiseImportError("Could not import upstash_vector python package. ""Please install it with `pip install upstash_vector`.")ifindex:ifnotisinstance(index,Index):raiseValueError("Passed index object should be an ""instance of upstash_vector.Index, "f"got {type(index)}")self._index=indexlogger.info("Using the index passed as parameter")ifasync_index:ifnotisinstance(async_index,AsyncIndex):raiseValueError("Passed index object should be an ""instance of upstash_vector.AsyncIndex, "f"got {type(async_index)}")self._async_index=async_indexlogger.info("Using the async index passed as parameter")ifindex_urlandindex_token:self._index=Index(url=index_url,token=index_token)self._async_index=AsyncIndex(url=index_url,token=index_token)logger.info("Created index from the index_url and index_token parameters")elifnotindexandnotasync_index:self._index=Index.from_env()self._async_index=AsyncIndex.from_env()logger.info("Created index using environment variables")self._embeddings=embeddingself._text_key=text_keyself._namespace=namespace
@propertydefembeddings(self)->Optional[Union[Embeddings,bool]]:# type: ignore"""Access the query embedding object if available."""returnself._embeddingsdef_embed_documents(self,texts:Iterable[str])->Union[List[List[float]],List[str]]:"""Embed strings using the embeddings object"""ifnotself._embeddings:raiseValueError("No embeddings object provided. ""Pass an embeddings object to the constructor.")ifisinstance(self._embeddings,Embeddings):returnself._embeddings.embed_documents(list(texts))# using self._embeddings is True, Upstash embeddings will be used.# returning list of text as List[str]returnlist(texts)def_embed_query(self,text:str)->Union[List[float],str]:"""Embed query text using the embeddings object."""ifnotself._embeddings:raiseValueError("No embeddings object provided. ""Pass an embeddings object to the constructor.")ifisinstance(self._embeddings,Embeddings):returnself._embeddings.embed_query(text)# using self._embeddings is True, Upstash embeddings will be used.# returning query as it isreturntext
[docs]defadd_documents(self,documents:List[Document],ids:Optional[List[str]]=None,batch_size:int=32,embedding_chunk_size:int=1000,*,namespace:Optional[str]=None,**kwargs:Any,)->List[str]:""" Get the embeddings for the documents and add them to the vectorstore. Documents are sent to the embeddings object in batches of size `embedding_chunk_size`. The embeddings are then upserted into the vectorstore in batches of size `batch_size`. Args: documents: Iterable of Documents to add to the vectorstore. batch_size: Batch size to use when upserting the embeddings. Upstash supports at max 1000 vectors per request. embedding_batch_size: Chunk size to use when embedding the texts. namespace: Namespace to use from the index. Returns: List of ids from adding the texts into the vectorstore. """texts=[doc.page_contentfordocindocuments]metadatas=[doc.metadatafordocindocuments]returnself.add_texts(texts,metadatas=metadatas,batch_size=batch_size,ids=ids,embedding_chunk_size=embedding_chunk_size,namespace=namespace,**kwargs,)
[docs]asyncdefaadd_documents(self,documents:Iterable[Document],ids:Optional[List[str]]=None,batch_size:int=32,embedding_chunk_size:int=1000,*,namespace:Optional[str]=None,**kwargs:Any,)->List[str]:""" Get the embeddings for the documents and add them to the vectorstore. Documents are sent to the embeddings object in batches of size `embedding_chunk_size`. The embeddings are then upserted into the vectorstore in batches of size `batch_size`. Args: documents: Iterable of Documents to add to the vectorstore. batch_size: Batch size to use when upserting the embeddings. Upstash supports at max 1000 vectors per request. embedding_batch_size: Chunk size to use when embedding the texts. namespace: Namespace to use from the index. Returns: List of ids from adding the texts into the vectorstore. """texts=[doc.page_contentfordocindocuments]metadatas=[doc.metadatafordocindocuments]returnawaitself.aadd_texts(texts,metadatas=metadatas,ids=ids,batch_size=batch_size,embedding_chunk_size=embedding_chunk_size,namespace=namespace,**kwargs,)
[docs]defadd_texts(self,texts:Iterable[str],metadatas:Optional[List[dict]]=None,ids:Optional[List[str]]=None,batch_size:int=32,embedding_chunk_size:int=1000,*,namespace:Optional[str]=None,**kwargs:Any,)->List[str]:""" Get the embeddings for the texts and add them to the vectorstore. Texts are sent to the embeddings object in batches of size `embedding_chunk_size`. The embeddings are then upserted into the vectorstore in batches of size `batch_size`. Args: texts: Iterable of strings to add to the vectorstore. metadatas: Optional list of metadatas associated with the texts. ids: Optional list of ids to associate with the texts. batch_size: Batch size to use when upserting the embeddings. Upstash supports at max 1000 vectors per request. embedding_batch_size: Chunk size to use when embedding the texts. namespace: Namespace to use from the index. Returns: List of ids from adding the texts into the vectorstore. """ifnamespaceisNone:namespace=self._namespacetexts=list(texts)ids=idsor[str(uuid.uuid4())for_intexts]# Copy metadatas to avoid modifying the original documentsifmetadatas:metadatas=[m.copy()forminmetadatas]else:metadatas=[{}for_intexts]# Add text to metadataformetadata,textinzip(metadatas,texts):metadata[self._text_key]=textforiinrange(0,len(texts),embedding_chunk_size):chunk_texts=texts[i:i+embedding_chunk_size]chunk_ids=ids[i:i+embedding_chunk_size]chunk_metadatas=metadatas[i:i+embedding_chunk_size]embeddings=self._embed_documents(chunk_texts)forbatchinbatch_iterate(batch_size,zip(chunk_ids,embeddings,chunk_metadatas)):self._index.upsert(vectors=batch,namespace=cast(str,namespace),**kwargs)returnids
[docs]asyncdefaadd_texts(self,texts:Iterable[str],metadatas:Optional[List[dict]]=None,ids:Optional[List[str]]=None,batch_size:int=32,embedding_chunk_size:int=1000,*,namespace:Optional[str]=None,**kwargs:Any,)->List[str]:""" Get the embeddings for the texts and add them to the vectorstore. Texts are sent to the embeddings object in batches of size `embedding_chunk_size`. The embeddings are then upserted into the vectorstore in batches of size `batch_size`. Args: texts: Iterable of strings to add to the vectorstore. metadatas: Optional list of metadatas associated with the texts. ids: Optional list of ids to associate with the texts. batch_size: Batch size to use when upserting the embeddings. Upstash supports at max 1000 vectors per request. embedding_batch_size: Chunk size to use when embedding the texts. namespace: Namespace to use from the index. Returns: List of ids from adding the texts into the vectorstore. """ifnamespaceisNone:namespace=self._namespacetexts=list(texts)ids=idsor[str(uuid.uuid4())for_intexts]# Copy metadatas to avoid modifying the original documentsifmetadatas:metadatas=[m.copy()forminmetadatas]else:metadatas=[{}for_intexts]# Add text to metadataformetadata,textinzip(metadatas,texts):metadata[self._text_key]=textforiinrange(0,len(texts),embedding_chunk_size):chunk_texts=texts[i:i+embedding_chunk_size]chunk_ids=ids[i:i+embedding_chunk_size]chunk_metadatas=metadatas[i:i+embedding_chunk_size]embeddings=self._embed_documents(chunk_texts)forbatchinbatch_iterate(batch_size,zip(chunk_ids,embeddings,chunk_metadatas)):awaitself._async_index.upsert(vectors=batch,namespace=cast(str,namespace),**kwargs)returnids
[docs]defsimilarity_search_with_score(self,query:str,k:int=4,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Tuple[Document,float]]:"""Retrieve texts most similar to query and convert the result to `Document` objects. Args: query: Text to look up documents similar to. k: Number of Documents to return. Defaults to 4. filter: Optional metadata filter in str format namespace: Namespace to use from the index. Returns: List of Documents most similar to the query and score for each """returnself.similarity_search_by_vector_with_score(self._embed_query(query),k=k,filter=filter,namespace=namespace,**kwargs)
[docs]asyncdefasimilarity_search_with_score(self,query:str,k:int=4,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Tuple[Document,float]]:"""Retrieve texts most similar to query and convert the result to `Document` objects. Args: query: Text to look up documents similar to. k: Number of Documents to return. Defaults to 4. filter: Optional metadata filter in str format namespace: Namespace to use from the index. Returns: List of Documents most similar to the query and score for each """returnawaitself.asimilarity_search_by_vector_with_score(self._embed_query(query),k=k,filter=filter,namespace=namespace,**kwargs)
def_process_results(self,results:List)->List[Tuple[Document,float]]:docs=[]forresinresults:metadata=res.metadataifmetadataandself._text_keyinmetadata:text=metadata.pop(self._text_key)doc=Document(page_content=text,metadata=metadata)docs.append((doc,res.score))else:logger.warning(f"Found document with no `{self._text_key}` key. Skipping.")returndocs
[docs]defsimilarity_search_by_vector_with_score(self,embedding:Union[List[float],str],k:int=4,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Tuple[Document,float]]:"""Return texts whose embedding is closest to the given embedding"""filter=filteror""ifnamespaceisNone:namespace=self._namespaceifisinstance(embedding,str):results=self._index.query(data=embedding,top_k=k,include_metadata=True,filter=filter,namespace=namespace,**kwargs,)else:results=self._index.query(vector=embedding,top_k=k,include_metadata=True,filter=filter,namespace=namespace,**kwargs,)returnself._process_results(results)
[docs]asyncdefasimilarity_search_by_vector_with_score(self,embedding:Union[List[float],str],k:int=4,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Tuple[Document,float]]:"""Return texts whose embedding is closest to the given embedding"""filter=filteror""ifnamespaceisNone:namespace=self._namespaceifisinstance(embedding,str):results=awaitself._async_index.query(data=embedding,top_k=k,include_metadata=True,filter=filter,namespace=namespace,**kwargs,)else:results=awaitself._async_index.query(vector=embedding,top_k=k,include_metadata=True,filter=filter,namespace=namespace,**kwargs,)returnself._process_results(results)
[docs]defsimilarity_search(self,query:str,k:int=4,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Document]:"""Return documents most similar to query. Args: query: Text to look up documents similar to. k: Number of Documents to return. Defaults to 4. filter: Optional metadata filter in str format namespace: Namespace to use from the index. Returns: List of Documents most similar to the query and score for each """docs_and_scores=self.similarity_search_with_score(query,k=k,filter=filter,namespace=namespace,**kwargs)return[docfordoc,_indocs_and_scores]
[docs]asyncdefasimilarity_search(self,query:str,k:int=4,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Document]:"""Return documents most similar to query. Args: query: Text to look up documents similar to. k: Number of Documents to return. Defaults to 4. filter: Optional metadata filter in str format namespace: Namespace to use from the index. Returns: List of Documents most similar to the query """docs_and_scores=awaitself.asimilarity_search_with_score(query,k=k,filter=filter,namespace=namespace,**kwargs)return[docfordoc,_indocs_and_scores]
[docs]defsimilarity_search_by_vector(self,embedding:Union[List[float],str],k:int=4,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Document]:"""Return documents closest to the given embedding. Args: embedding: Embedding to look up documents similar to. k: Number of Documents to return. Defaults to 4. filter: Optional metadata filter in str format namespace: Namespace to use from the index. Returns: List of Documents most similar to the query """docs_and_scores=self.similarity_search_by_vector_with_score(embedding,k=k,filter=filter,namespace=namespace,**kwargs)return[docfordoc,_indocs_and_scores]
[docs]asyncdefasimilarity_search_by_vector(self,embedding:Union[List[float],str],k:int=4,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Document]:"""Return documents closest to the given embedding. Args: embedding: Embedding to look up documents similar to. k: Number of Documents to return. Defaults to 4. filter: Optional metadata filter in str format namespace: Namespace to use from the index. Returns: List of Documents most similar to the query """docs_and_scores=awaitself.asimilarity_search_by_vector_with_score(embedding,k=k,filter=filter,namespace=namespace,**kwargs)return[docfordoc,_indocs_and_scores]
def_similarity_search_with_relevance_scores(self,query:str,k:int=4,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Tuple[Document,float]]:""" Since Upstash always returns relevance scores, default implementation is used. """returnself.similarity_search_with_score(query,k=k,filter=filter,namespace=namespace,**kwargs)asyncdef_asimilarity_search_with_relevance_scores(self,query:str,k:int=4,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Tuple[Document,float]]:""" Since Upstash always returns relevance scores, default implementation is used. """returnawaitself.asimilarity_search_with_score(query,k=k,filter=filter,namespace=namespace,**kwargs)
[docs]defmax_marginal_relevance_search_by_vector(self,embedding:Union[List[float],str],k:int=4,fetch_k:int=20,lambda_mult:float=0.5,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Document]:"""Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Args: embedding: Embedding 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. lambda_mult: 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. filter: Optional metadata filter in str format namespace: Namespace to use from the index. Returns: List of Documents selected by maximal marginal relevance. """ifnamespaceisNone:namespace=self._namespaceassertisinstance(self.embeddings,Embeddings)ifisinstance(embedding,str):results=self._index.query(data=embedding,top_k=fetch_k,include_vectors=True,include_metadata=True,filter=filteror"",namespace=namespace,**kwargs,)else:results=self._index.query(vector=embedding,top_k=fetch_k,include_vectors=True,include_metadata=True,filter=filteror"",namespace=namespace,**kwargs,)mmr_selected=maximal_marginal_relevance(np.array([embedding],dtype=np.float32),[item.vectorforiteminresults],k=k,lambda_mult=lambda_mult,)selected=[results[i].metadataforiinmmr_selected]return[Document(page_content=metadata.pop((self._text_key)),metadata=metadata)# type: ignoreformetadatainselected]
[docs]asyncdefamax_marginal_relevance_search_by_vector(self,embedding:Union[List[float],str],k:int=4,fetch_k:int=20,lambda_mult:float=0.5,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Document]:"""Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents. Args: embedding: Embedding 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. lambda_mult: 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. filter: Optional metadata filter in str format namespace: Namespace to use from the index. Returns: List of Documents selected by maximal marginal relevance. """ifnamespaceisNone:namespace=self._namespaceassertisinstance(self.embeddings,Embeddings)ifisinstance(embedding,str):results=awaitself._async_index.query(data=embedding,top_k=fetch_k,include_vectors=True,include_metadata=True,filter=filteror"",namespace=namespace,**kwargs,)else:results=awaitself._async_index.query(vector=embedding,top_k=fetch_k,include_vectors=True,include_metadata=True,filter=filteror"",namespace=namespace,**kwargs,)mmr_selected=maximal_marginal_relevance(np.array([embedding],dtype=np.float32),[item.vectorforiteminresults],k=k,lambda_mult=lambda_mult,)selected=[results[i].metadataforiinmmr_selected]return[Document(page_content=metadata.pop((self._text_key)),metadata=metadata)# type: ignoreformetadatainselected]
[docs]defmax_marginal_relevance_search(self,query:str,k:int=4,fetch_k:int=20,lambda_mult:float=0.5,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Document]:"""Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity 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. lambda_mult: 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. filter: Optional metadata filter in str format namespace: Namespace to use from the index. Returns: List of Documents selected by maximal marginal relevance. """embedding=self._embed_query(query)returnself.max_marginal_relevance_search_by_vector(embedding=embedding,k=k,fetch_k=fetch_k,lambda_mult=lambda_mult,filter=filter,namespace=namespace,**kwargs,)
[docs]asyncdefamax_marginal_relevance_search(self,query:str,k:int=4,fetch_k:int=20,lambda_mult:float=0.5,filter:Optional[str]=None,*,namespace:Optional[str]=None,**kwargs:Any,)->List[Document]:"""Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity 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. lambda_mult: 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. filter: Optional metadata filter in str format namespace: Namespace to use from the index. Returns: List of Documents selected by maximal marginal relevance. """embedding=self._embed_query(query)returnawaitself.amax_marginal_relevance_search_by_vector(embedding=embedding,k=k,fetch_k=fetch_k,lambda_mult=lambda_mult,filter=filter,namespace=namespace,**kwargs,)
[docs]@classmethoddeffrom_texts(cls,texts:List[str],embedding:Embeddings,metadatas:Optional[List[dict]]=None,ids:Optional[List[str]]=None,embedding_chunk_size:int=1000,batch_size:int=32,text_key:str="text",index:Optional[Index]=None,async_index:Optional[AsyncIndex]=None,index_url:Optional[str]=None,index_token:Optional[str]=None,*,namespace:str="",**kwargs:Any,)->UpstashVectorStore:"""Create a new UpstashVectorStore from a list of texts. Example: .. code-block:: python from langchain_community.vectorstores.upstash import UpstashVectorStore from langchain_community.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() vector_store = UpstashVectorStore.from_texts( texts, embeddings, ) """vector_store=cls(embedding=embedding,text_key=text_key,index=index,async_index=async_index,index_url=index_url,index_token=index_token,namespace=namespace,**kwargs,)vector_store.add_texts(texts,metadatas=metadatas,ids=ids,batch_size=batch_size,embedding_chunk_size=embedding_chunk_size,namespace=namespace,)returnvector_store
[docs]@classmethodasyncdefafrom_texts(cls,texts:List[str],embedding:Embeddings,metadatas:Optional[List[dict]]=None,ids:Optional[List[str]]=None,embedding_chunk_size:int=1000,batch_size:int=32,text_key:str="text",index:Optional[Index]=None,async_index:Optional[AsyncIndex]=None,index_url:Optional[str]=None,index_token:Optional[str]=None,*,namespace:str="",**kwargs:Any,)->UpstashVectorStore:"""Create a new UpstashVectorStore from a list of texts. Example: .. code-block:: python from langchain_community.vectorstores.upstash import UpstashVectorStore from langchain_community.embeddings import OpenAIEmbeddings embeddings = OpenAIEmbeddings() vector_store = UpstashVectorStore.from_texts( texts, embeddings, ) """vector_store=cls(embedding=embedding,text_key=text_key,index=index,async_index=async_index,namespace=namespace,index_url=index_url,index_token=index_token,**kwargs,)awaitvector_store.aadd_texts(texts,metadatas=metadatas,ids=ids,batch_size=batch_size,namespace=namespace,embedding_chunk_size=embedding_chunk_size,)returnvector_store
[docs]defdelete(self,ids:Optional[List[str]]=None,delete_all:Optional[bool]=None,batch_size:Optional[int]=1000,*,namespace:Optional[str]=None,**kwargs:Any,)->None:"""Delete by vector IDs Args: ids: List of ids to delete. delete_all: Delete all vectors in the index. batch_size: Batch size to use when deleting the embeddings. namespace: Namespace to use from the index. Upstash supports at max 1000 deletions per request. """ifnamespaceisNone:namespace=self._namespaceifdelete_all:self._index.reset(namespace=namespace)elifidsisnotNone:forbatchinbatch_iterate(batch_size,ids):self._index.delete(ids=batch,namespace=namespace)else:raiseValueError("Either ids or delete_all should be provided")returnNone
[docs]asyncdefadelete(self,ids:Optional[List[str]]=None,delete_all:Optional[bool]=None,batch_size:Optional[int]=1000,*,namespace:Optional[str]=None,**kwargs:Any,)->None:"""Delete by vector IDs Args: ids: List of ids to delete. delete_all: Delete all vectors in the index. batch_size: Batch size to use when deleting the embeddings. namespace: Namespace to use from the index. Upstash supports at max 1000 deletions per request. """ifnamespaceisNone:namespace=self._namespaceifdelete_all:awaitself._async_index.reset(namespace=namespace)elifidsisnotNone:forbatchinbatch_iterate(batch_size,ids):awaitself._async_index.delete(ids=batch,namespace=namespace)else:raiseValueError("Either ids or delete_all should be provided")returnNone
[docs]definfo(self)->InfoResult:"""Get statistics about the index. Returns: - total number of vectors - total number of vectors waiting to be indexed - total size of the index on disk in bytes - dimension count for the index - similarity function selected for the index """returnself._index.info()
[docs]asyncdefainfo(self)->InfoResult:"""Get statistics about the index. Returns: - total number of vectors - total number of vectors waiting to be indexed - total size of the index on disk in bytes - dimension count for the index - similarity function selected for the index """returnawaitself._async_index.info()