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
-
Method Summary
Modifier and TypeMethodDescriptionRun more texts through the embeddings and add to the vectorStore.void
void
Delete by vector ID.int
Initializes 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:VectorStore
Run more texts through the embeddings and add to the vectorStore.- Specified by:
addTexts
in 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:VectorStore
Delete by vector ID.- Specified by:
delete
in classVectorStore
- Parameters:
ids
- List of ids to delete.
-
similaritySearch
Description copied from class:VectorStore
Returns the documents most similar to the given query.- Specified by:
similaritySearch
in 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:VectorStore
Return docs and relevance scores, normalized on a scale from 0 to 1. 0 is dissimilar, 1 is most similar.- Specified by:
innerSimilaritySearchWithRelevanceScores
in 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:VectorStore
Return docs most similar to embedding vector.- Specified by:
similarSearchByVector
in 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:VectorStore
Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.- Specified by:
maxMarginalRelevanceSearch
in 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:VectorStore
Return docs selected using the maximal marginal relevance. Maximal marginal relevance optimizes for similarity to query AND diversity among selected documents.- Specified by:
maxMarginalRelevanceSearchByVector
in 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:VectorStore
Initializes and returns a VectorStore from the given texts, embeddings, and metadata.- Specified by:
fromTexts
in classVectorStore
- Parameters:
texts
- the list of textsembedding
- the embeddings for the textsmetadatas
- the list of metadata associated with the texts- Returns:
- the initialized VectorStore
-