Integrations LangChain question answering with self query retriever

This workbook demonstrates example of Elasticsearch's Self-query retriever to convert a question into a structured query and apply structured query to Elasticsearch index.

Before we begin, we first split the documents into chunks with langchain and then using ElasticsearchStore.from_documents, we create a vectorstore and index data to elasticsearch.

We will then see few examples query demonstrating full power of elasticsearch powered self-query retriever.

Install packages and import modules

[notice] A new release of pip is available: 23.2 -> 23.3.1 [notice] To update, run: pip install --upgrade pip

Create documents

Next, we will create list of documents with summary of movies using langchain Schema Document, containing each document's page_content and metadata .

Connect to Elasticsearch

ℹ️ We're using an Elastic Cloud deployment of Elasticsearch for this notebook. If you don't have an Elastic Cloud deployment, sign up here for a free trial.

We'll use the Cloud ID to identify our deployment, because we are using Elastic Cloud deployment. To find the Cloud ID for your deployment, go to https://cloud.elastic.co/deployments and select your deployment.

We will use ElasticsearchStore to connect to our elastic cloud deployment, This would help create and index data easily. We would also send list of documents that we created in the previous step.

Setup query retriever

Next we will instantiate self-query retriever by providing a bit information about our document attributes and a short description about the document.

We will then instantiate retriever with SelfQueryRetriever.from_llm

We will now demonstrate how to use self-query retriever for RAG.

AIMessage(content='Inception (2010)')

최첨단 검색 환경을 구축할 준비가 되셨나요?

충분히 고급화된 검색은 한 사람의 노력만으로는 달성할 수 없습니다. Elasticsearch는 여러분과 마찬가지로 검색에 대한 열정을 가진 데이터 과학자, ML 운영팀, 엔지니어 등 많은 사람들이 지원합니다. 서로 연결하고 협력하여 원하는 결과를 얻을 수 있는 마법 같은 검색 환경을 구축해 보세요.

직접 사용해 보세요