Class Milvus
java.lang.Object
com.hw.langchain.vectorstores.base.VectorStore
com.hw.langchain.vectorstores.milvus.Milvus
Initialize wrapper around the milvus vector database.
- Author:
- HamaWhite
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionRun more texts through the embeddings and add to the vectorStore.voidvoidDelete by vector ID.intInitializes and returns a VectorStore from the given texts, embeddings, and metadata.init()innerSimilaritySearchWithRelevanceScores(String query, int k) Return docs and relevance scores, normalized on a scale from 0 to 1.maxMarginalRelevanceSearch(String query, int k, int fetchK, float lambdaMult) Return docs selected using the maximal marginal relevance.maxMarginalRelevanceSearchByVector(List<Float> embedding, int k, int fetchK, float lambdaMult) Return docs selected using the maximal marginal relevance.similaritySearch(String query, int k, Map<String, Object> filter) Returns the documents most similar to the given query.Return docs most similar to embedding vector.Methods inherited from class com.hw.langchain.vectorstores.base.VectorStore
addDocuments, asRetriever, asRetriever, fromDocuments, maxMarginalRelevanceSearch, maxMarginalRelevanceSearchByVector, search, similaritySearch, similaritySearch, similaritySearchWithRelevanceScores, similaritySearchWithRelevanceScores
-
Constructor Details
-
Milvus
public Milvus()
-
-
Method Details
-
init
-
createCollection
-
addTexts
Description copied from class:VectorStoreRun more texts through the embeddings and add to the vectorStore.- Specified by:
addTextsin classVectorStore- Parameters:
texts- Iterable of strings to add to the vectorStore.metadatas- list of metadatas associated with the texts.- Returns:
- List of ids from adding the texts into the vectorStore.
-
delete
Description copied from class:VectorStoreDelete by vector ID.- Specified by:
deletein classVectorStore- Parameters:
ids- List of ids to delete.
-
similaritySearch
Description copied from class:VectorStoreReturns the documents most similar to the given query.- Specified by:
similaritySearchin classVectorStore- Parameters:
query- the input textk- the number of documents to returnfilter- a filter to apply to the search- Returns:
- a list of tuples containing the documents and their similarity scores
-
innerSimilaritySearchWithRelevanceScores
protected List<org.apache.commons.lang3.tuple.Pair<Document,Float>> innerSimilaritySearchWithRelevanceScores(String query, int k) Description copied from class:VectorStoreReturn docs and relevance scores, normalized on a scale from 0 to 1. 0 is dissimilar, 1 is most similar.- Specified by:
innerSimilaritySearchWithRelevanceScoresin classVectorStore- Parameters:
query- input textk- Number of Documents to return.- Returns:
- List of Tuples of (doc, similarityScore)
-
similarSearchByVector
public List<Document> similarSearchByVector(List<Float> embedding, int k, Map<String, Object> kwargs) Description copied from class:VectorStoreReturn docs most similar to embedding vector.- Specified by:
similarSearchByVectorin classVectorStore- Parameters:
embedding- Embedding to look up documents similar to.k- Number of Documents to return. Defaults to 4.kwargs- kwargs to be passed to similarity search- Returns:
- List of Documents most similar to the query vector.
-
maxMarginalRelevanceSearch
Description copied from class:VectorStoreReturn docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.- Specified by:
maxMarginalRelevanceSearchin classVectorStore- Parameters:
query- Text to look up documents similar to.k- Number of Documents to return.fetchK- Number of Documents to fetch to pass to MMR algorithm.lambdaMult- 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.- Returns:
- List of Documents selected by maximal marginal relevance.
-
maxMarginalRelevanceSearchByVector
public List<Document> maxMarginalRelevanceSearchByVector(List<Float> embedding, int k, int fetchK, float lambdaMult) Description copied from class:VectorStoreReturn docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.- Specified by:
maxMarginalRelevanceSearchByVectorin classVectorStore- Parameters:
embedding- Embedding to look up documents similar to.k- Number of Documents to return.fetchK- Number of Documents to fetch to pass to MMR algorithm.lambdaMult- 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.- Returns:
- List of Documents selected by maximal marginal relevance.
-
fromTexts
Description copied from class:VectorStoreInitializes and returns a VectorStore from the given texts, embeddings, and metadata.- Specified by:
fromTextsin classVectorStore- Parameters:
texts- the list of textsembedding- the embeddings for the textsmetadatas- the list of metadata associated with the texts- Returns:
- the initialized VectorStore
-