Skip to content

Add self-query advisor #1019

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open

Conversation

florind
Copy link

@florind florind commented Jul 9, 2024

  • Add a SelfQueryAdvisor that follows LangChain's SelfQueryRetriever:
    Specifically, given any natural language query, the retriever uses a query-constructing LLM chain to write a structured query and then applies that structured query to its underlying VectorStore.
  • The prompt is taken from here
  • To be able to extract query attributes, a list of AttributeInfo objects must be specified. This instructs the LLM to identify attributes in the given user query then query the vector store using the metadata attributes.
  • Example:
        var selfQueryAdvisor = SelfQueryAdvisor(
          listOf(
                AttributeInfo(
                name = "firstName",
                type = "string",
                description = "A person's first name"),
          ),
          vectorStore,
          SearchRequest.defaults(),
          chatModel,
        );
       
        var response = chatClient.prompt()
                         .advisors(selfQueryAdvisor)
                         .user("Return a list of persons whose first name is Kylian").chatResponse();

@florind florind changed the title Add self-query implementation Add self-query advisor Jul 9, 2024
@tzolov
Copy link
Contributor

tzolov commented Jul 17, 2024

Hi @florind and thank you for the contribution.
Interesting stuff! Let me dig a bit through the LangChain docs

@tzolov tzolov self-assigned this Jul 17, 2024
@florind florind mentioned this pull request Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants