Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

core: Add async methods to BaseExampleSelector and SemanticSimilarityExampleSelector #19399

Merged
merged 1 commit into from
Mar 26, 2024

Conversation

cbornet
Copy link
Collaborator

@cbornet cbornet commented Mar 21, 2024

Few-Shot prompt template may use a SemanticSimilarityExampleSelector that in turn uses a VectorStore that does I/O operations.
So to work correctly on the event loop, we need:

  • async methods for the VectorStore (OK)
  • async methods for the SemanticSimilarityExampleSelector (this PR)
  • async methods for BasePromptTemplate and BaseChatPromptTemplate (future work)

@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Mar 21, 2024
Copy link

vercel bot commented Mar 21, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Visit Preview Mar 21, 2024 2:23pm

@dosubot dosubot bot added Ɑ: core Related to langchain-core 🔌: openai Primarily related to OpenAI integrations 🤖:improvement Medium size change to existing code to handle new use-cases labels Mar 21, 2024
@cbornet cbornet force-pushed the async-example-selector branch 3 times, most recently from 9b42695 to 426dea1 Compare March 21, 2024 14:19
@cbornet cbornet force-pushed the async-example-selector branch from 426dea1 to 859c6e9 Compare March 21, 2024 14:23
@eyurtsev eyurtsev self-assigned this Mar 21, 2024
@eyurtsev eyurtsev self-requested a review March 25, 2024 20:28
@dosubot dosubot bot added the lgtm PR looks good. Use to confirm that a PR is ready for merging. label Mar 25, 2024
else:
return " ".join(sorted_values(example))

def _documents_to_examples(self, documents: List[Document]) -> List[dict]:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question -- why a static method for example to text vs. _documents_to_examples being a regular method

Are implementation providers going to need to override documents to examples based on some state available in self?

Copy link
Collaborator Author

@cbornet cbornet Mar 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can’t make this one static as it uses self.example_keys.
In _document_to_example, input_keys is passed as argument instead so it can be called from the classmethod from_examples.

@eyurtsev eyurtsev added the waiting-on-author PR Status: Confirmation from author is required label Mar 25, 2024
@eyurtsev
Copy link
Collaborator

Ready to merge, just need confirmation from @cbornet on whether static methods vs. regular methods should be used -- do we forsee the need to use state. If so maybe a doc-string for those methods could be added to explain how to sub-class correctly and which methods are meant to be overriden?

@cbornet
Copy link
Collaborator Author

cbornet commented Mar 26, 2024

If so maybe a doc-string for those methods could be added to explain how to sub-class correctly and which methods are meant to be overriden?

Those methods are internal to the class and only there to factorize between sync and async. They are not meant to be overridden. Would you prefer a double-underscore ?

@eyurtsev
Copy link
Collaborator

@cbornet i usually pull things out into functions if they're not meant to be overridden -- otherwise folks will end up overriding them, especially since we have a bunch of examples where the correct way to do the implementation is by overriding a private method :(

I'll put out the code into functions in a few

@eyurtsev eyurtsev merged commit a9457d2 into langchain-ai:master Mar 26, 2024
95 checks passed
@eyurtsev
Copy link
Collaborator

eyurtsev commented Mar 26, 2024

I will do in a separate PR

@cbornet cbornet deleted the async-example-selector branch March 26, 2024 15:15
gkorland pushed a commit to FalkorDB/langchain that referenced this pull request Mar 30, 2024
…ExampleSelector (langchain-ai#19399)

Few-Shot prompt template may use a `SemanticSimilarityExampleSelector`
that in turn uses a `VectorStore` that does I/O operations.
So to work correctly on the event loop, we need:
* async methods for the `VectorStore` (OK)
* async methods for the `SemanticSimilarityExampleSelector` (this PR)
* async methods for `BasePromptTemplate` and `BaseChatPromptTemplate`
(future work)
hinthornw pushed a commit that referenced this pull request Apr 26, 2024
…ExampleSelector (#19399)

Few-Shot prompt template may use a `SemanticSimilarityExampleSelector`
that in turn uses a `VectorStore` that does I/O operations.
So to work correctly on the event loop, we need:
* async methods for the `VectorStore` (OK)
* async methods for the `SemanticSimilarityExampleSelector` (this PR)
* async methods for `BasePromptTemplate` and `BaseChatPromptTemplate`
(future work)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ɑ: core Related to langchain-core 🤖:improvement Medium size change to existing code to handle new use-cases lgtm PR looks good. Use to confirm that a PR is ready for merging. 🔌: openai Primarily related to OpenAI integrations size:L This PR changes 100-499 lines, ignoring generated files. waiting-on-author PR Status: Confirmation from author is required
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants