Skip to content

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
@markpollack markpollack added the enhancement New feature or request label Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
advisors enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants