Class VespaEmbeddingStore

java.lang.Object
dev.langchain4j.store.embedding.vespa.VespaEmbeddingStore
All Implemented Interfaces:
EmbeddingStore<TextSegment>

public class VespaEmbeddingStore extends Object implements EmbeddingStore<TextSegment>
Represents the Vespa - search engine and vector database. Does not support storing Metadata yet. Example server configuration contains cosine similarity search rank profile, of course other Vespa neighbor search methods are supported too. Read more here.
  • Constructor Details

    • VespaEmbeddingStore

      public VespaEmbeddingStore(String url, String keyPath, String certPath, Duration timeout, String namespace, String documentType, String rankProfile, Integer targetHits, Boolean avoidDups)
      Creates a new VespaEmbeddingStore instance.
      Parameters:
      url - server url, local or cloud one. The latter you can find under Endpoint of your Vespa application, e.g. https://alexey-heezer.langchain4j.mytenant346.aws-us-east-1c.dev.z.vespa-app.cloud/
      keyPath - local path to the SSL private key file in PEM format. Read docs for details.
      certPath - local path to the SSL certificate file in PEM format. Read docs for details.
      timeout - for Vespa Java client in java.time.Duration format.
      namespace - required for document ID generation, find more details here.
      documentType - document type, used for document ID generation, find more details here and data querying
      rankProfile - rank profile from your .sd schema. Provided example schema configures cosine similarity match
      targetHits - sets the number of hits (10 is default) exposed to the real Vespa's first-phase ranking function per content node, find more details here.
      avoidDups - if true (default), then VespaEmbeddingStore will generate a hashed ID based on provided text segment, which avoids duplicated entries in DB. If false, then random ID will be generated.
  • Method Details

    • add

      public String add(Embedding embedding)
      Description copied from interface: EmbeddingStore
      Adds a given embedding to the store.
      Specified by:
      add in interface EmbeddingStore<TextSegment>
      Parameters:
      embedding - The embedding to be added to the store.
      Returns:
      The auto-generated ID associated with the added embedding.
    • add

      public void add(String id, Embedding embedding)
      Adds a new embedding with provided ID to the store.
      Specified by:
      add in interface EmbeddingStore<TextSegment>
      Parameters:
      id - "user-specified" part of document ID, find more details here
      embedding - the embedding to add
    • add

      public String add(Embedding embedding, TextSegment textSegment)
      Description copied from interface: EmbeddingStore
      Adds a given embedding and the corresponding content that has been embedded to the store.
      Specified by:
      add in interface EmbeddingStore<TextSegment>
      Parameters:
      embedding - The embedding to be added to the store.
      textSegment - Original content that was embedded.
      Returns:
      The auto-generated ID associated with the added embedding.
    • addAll

      public List<String> addAll(List<Embedding> embeddings)
      Description copied from interface: EmbeddingStore
      Adds multiple embeddings to the store.
      Specified by:
      addAll in interface EmbeddingStore<TextSegment>
      Parameters:
      embeddings - A list of embeddings to be added to the store.
      Returns:
      A list of auto-generated IDs associated with the added embeddings.
    • addAll

      public List<String> addAll(List<Embedding> embeddings, List<TextSegment> embedded)
      Description copied from interface: EmbeddingStore
      Adds multiple embeddings and their corresponding contents that have been embedded to the store.
      Specified by:
      addAll in interface EmbeddingStore<TextSegment>
      Parameters:
      embeddings - A list of embeddings to be added to the store.
      embedded - A list of original contents that were embedded.
      Returns:
      A list of auto-generated IDs associated with the added embeddings.
    • findRelevant

      public List<EmbeddingMatch<TextSegment>> findRelevant(Embedding referenceEmbedding, int maxResults, double minScore)
      Finds the most relevant (closest in space) embeddings to the provided reference embedding. The score inside EmbeddingMatch is Vespa relevance according to provided rank profile.
      Specified by:
      findRelevant in interface EmbeddingStore<TextSegment>
      Parameters:
      referenceEmbedding - The embedding used as a reference. Returned embeddings should be relevant (closest) to this one.
      maxResults - The maximum number of embeddings to be returned.
      minScore - The minimum relevance score, ranging from 0 to 1 (inclusive). Only embeddings with a score of this value or higher will be returned.
      Returns:
      A list of embedding matches. Each embedding match includes a relevance score (derivative of cosine distance), ranging from 0 (not relevant) to 1 (highly relevant).