Class Pinecone

java.lang.Object
com.hw.langchain.vectorstores.base.VectorStore
com.hw.langchain.vectorstores.pinecone.Pinecone

public class Pinecone extends VectorStore
Author:
HamaWhite
  • Constructor Details

    • Pinecone

      public Pinecone()
  • Method Details

    • init

      public Pinecone init()
      Validate parameters and init client
    • addTexts

      public List<String> addTexts(List<String> texts, List<Map<String,Object>> metadatas)
      Description copied from class: VectorStore
      Run more texts through the embeddings and add to the vectorStore.
      Specified by:
      addTexts in class VectorStore
      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

      public void delete(List<String> ids)
      Description copied from class: VectorStore
      Delete by vector ID.
      Specified by:
      delete in class VectorStore
      Parameters:
      ids - List of ids to delete.
    • similaritySearch

      public List<Document> similaritySearch(String query, int k, Map<String,Object> filter)
      Return pinecone documents most similar to query.
      Specified by:
      similaritySearch in class VectorStore
      Parameters:
      query - Text to look up documents similar to.
      k - Number of Documents to return. Defaults to 4.
      filter - Dictionary of argument(s) to filter on metadata
      Returns:
      List of Documents most similar to the query and score for each
    • 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 class VectorStore
      Parameters:
      query - input text
      k - 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 class VectorStore
      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

      public List<Document> maxMarginalRelevanceSearch(String query, 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:
      maxMarginalRelevanceSearch in class VectorStore
      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 class VectorStore
      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

      public int fromTexts(List<String> texts, Embeddings embedding, List<Map<String,Object>> metadatas)
      Description copied from class: VectorStore
      Initializes and returns a VectorStore from the given texts, embeddings, and metadata.
      Specified by:
      fromTexts in class VectorStore
      Parameters:
      texts - the list of texts
      embedding - the embeddings for the texts
      metadatas - the list of metadata associated with the texts
      Returns:
      the initialized VectorStore