Skip to content

Conversation

@nidzola
Copy link
Contributor

@nidzola nidzola commented Aug 11, 2023

PR Checklist

  • Read the Contributing documentation.
  • Read the Code of conduct documentation.
  • Name your Pull Request title clearly, concisely, and prefixed with the name of the primarily affected package you changed according to Good commit messages (such as memory: add interfaces for X, Y or util: add whizzbang helpers).
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. Fixes #123).
  • Describes the source of new concepts.
  • References existing implementations as appropriate.
  • Contains test coverage for new functions.
  • Passes all golangci-lint checks.

Description

  • this option allows us to use different embedders, if we have single vectorstore (like posgresql) which can handle (storing/using) multiple embeddings.

Usage example:

....
        // dummy list of embedders
        embedders := map[string]embedder.Embedder{
		"openai": openaiEmbedder,
		"huggingface": huggingfaceEmbedder,
		"vertexai": vertexaiEmbedder,
		"someother": someotherEmbedder,
	}
        emd := embedders["openai"] // dummy example pulling the embedders from the list of supported embedders

 	result, err := chains.Run(
		context.TODO(),
		chains.NewRetrievalQAFromLLM(
			llm,
			vectorstores.ToRetriever(store, 5, vectorstores.WithNameSpace(id), vectorstore.WithEmbedder(emb)),
		),
		"What colors is each piece of furniture next to the desk?",
	)
....

from this point on, our store when the AddDocuments or SimilaritySearch methods are called from the vectorstore interface, we can actually use the needed embedder and not be tied to only one.

for example

// Store is a wrapper around the pinecone rest API and grpc client.
type Store struct {
	some store configuration where we could have or not have embedder
}

funct (s Store) AddDocuments(ctx context.Context, docs []schema.Document, options ...vectorstores.Option) error {
     opts := v.getOptions(options...)
     vectors, err := options.Embeder.EmbedDocuments(ctx, texts)
   ....
}

@nidzola
Copy link
Contributor Author

nidzola commented Aug 11, 2023

@tmc

@tmc tmc merged commit 870f832 into tmc:main Aug 11, 2023
@nidzola nidzola deleted the vectorstore-embedder-options branch August 12, 2023 07:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants