Skip to content

Commit

Permalink
Update LangChain imports to use langchain-elasticsearch (#196)
Browse files Browse the repository at this point in the history
* Update LangChain imports to use `langchain-elasticsearch`

the new partner integration package:
https://pypi.org/project/langchain-elasticsearch/

* update chatbot-rag-app
  • Loading branch information
maxjakob authored Mar 5, 2024
1 parent 0eb5301 commit dfb9266
Show file tree
Hide file tree
Showing 18 changed files with 62 additions and 49 deletions.
2 changes: 1 addition & 1 deletion example-apps/chatbot-rag-app/api/chat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from langchain.vectorstores import ElasticsearchStore
from langchain_elasticsearch import ElasticsearchStore
from llm_integrations import get_llm
from elasticsearch_client import (
elasticsearch_client,
Expand Down
2 changes: 1 addition & 1 deletion example-apps/chatbot-rag-app/api/elasticsearch_client.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from elasticsearch import Elasticsearch
from langchain.memory import ElasticsearchChatMessageHistory
from langchain_elasticsearch import ElasticsearchChatMessageHistory

import os

Expand Down
2 changes: 1 addition & 1 deletion example-apps/chatbot-rag-app/data/index_data.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from elasticsearch import Elasticsearch, NotFoundError
from langchain.vectorstores import ElasticsearchStore
from langchain_elasticsearch import ElasticsearchStore
from langchain.docstore.document import Document
from langchain.text_splitter import RecursiveCharacterTextSplitter
from dotenv import load_dotenv
Expand Down
1 change: 1 addition & 0 deletions example-apps/chatbot-rag-app/requirements.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pip-tools
# core dependencies
elasticsearch
langchain
langchain-elasticsearch
tiktoken
flask
flask-cors
Expand Down
50 changes: 32 additions & 18 deletions example-apps/chatbot-rag-app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ aiosignal==1.3.1
annotated-types==0.5.0
# via pydantic
anyio==3.7.1
# via langchain
# via
# langchain
# langchain-core
async-timeout==4.0.3
# via aiohttp
attrs==23.1.0
Expand All @@ -27,9 +29,7 @@ botocore==1.31.61
# boto3
# s3transfer
build==1.0.3
# via
# -r requirements.in
# pip-tools
# via pip-tools
cachetools==5.3.1
# via google-auth
certifi==2023.7.22
Expand All @@ -48,8 +48,10 @@ dataclasses-json==0.5.14
# via langchain
elastic-transport==8.4.0
# via elasticsearch
elasticsearch==8.9.0
# via -r requirements.in
elasticsearch==8.12.1
# via
# -r requirements.in
# langchain-elasticsearch
exceptiongroup==1.2.0
# via -r requirements.in
flask==2.3.3
Expand Down Expand Up @@ -126,13 +128,21 @@ jmespath==1.0.1
# boto3
# botocore
jsonpatch==1.33
# via langchain
# via
# langchain
# langchain-core
jsonpointer==2.4
# via jsonpatch
langchain==0.0.333
# via -r requirements.in
langsmith==0.0.65
# via langchain
langchain-core==0.1.23
# via langchain-elasticsearch
langchain-elasticsearch==0.1.0
# via -r requirements.in
langsmith==0.0.87
# via
# langchain
# langchain-core
markupsafe==2.1.3
# via
# jinja2
Expand All @@ -150,15 +160,17 @@ numexpr==2.8.5
numpy==1.25.2
# via
# langchain
# langchain-elasticsearch
# numexpr
# shapely
openai==0.27.9
# via -r requirements.in
packaging==23.1
packaging==23.2
# via
# build
# google-cloud-aiplatform
# google-cloud-bigquery
# langchain-core
# marshmallow
pip-tools==7.3.0
# via -r requirements.in
Expand Down Expand Up @@ -186,21 +198,22 @@ pyasn1-modules==0.3.0
pydantic==2.3.0
# via
# langchain
# langchain-core
# langsmith
pydantic-core==2.6.3
# via pydantic
pyproject-hooks==1.0.0
# via
# -r requirements.in
# build
# via build
python-dateutil==2.8.2
# via
# botocore
# google-cloud-bigquery
python-dotenv==1.0.0
# via -r requirements.in
pyyaml==6.0.1
# via langchain
# via
# langchain
# langchain-core
regex==2023.10.3
# via tiktoken
requests==2.31.0
Expand All @@ -209,6 +222,7 @@ requests==2.31.0
# google-cloud-bigquery
# google-cloud-storage
# langchain
# langchain-core
# langsmith
# openai
# tiktoken
Expand All @@ -225,7 +239,9 @@ sniffio==1.3.0
sqlalchemy==2.0.20
# via langchain
tenacity==8.2.3
# via langchain
# via
# langchain
# langchain-core
tiktoken==0.5.1
# via -r requirements.in
tqdm==4.66.1
Expand All @@ -250,9 +266,7 @@ wheel==0.41.3
yarl==1.9.2
# via aiohttp
zipp==3.17.0
# via
# -r requirements.in
# importlib-metadata
# via importlib-metadata

# The following packages are considered to be unsafe in a requirements file:
# pip
Expand Down
4 changes: 2 additions & 2 deletions notebooks/document-chunking/with-langchain-splitters.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"metadata": {},
"outputs": [],
"source": [
"!python3 -m pip install -qU langchain elasticsearch eland jq"
"!python3 -m pip install -qU langchain langchain-elasticsearch elasticsearch eland jq"
]
},
{
Expand Down Expand Up @@ -548,7 +548,7 @@
}
],
"source": [
"from langchain.vectorstores.elasticsearch import (\n",
"from langchain_elasticsearch import (\n",
" ElasticsearchStore,\n",
" ApproxRetrievalStrategy,\n",
")\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/generative-ai/chatbot.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
}
],
"source": [
"%pip install -qU langchain openai elasticsearch tiktoken"
"%pip install -qU langchain openai langchain-elasticsearch tiktoken"
]
},
{
Expand Down Expand Up @@ -195,7 +195,7 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from langchain.embeddings import OpenAIEmbeddings\n",
"\n",
"embeddings = OpenAIEmbeddings(openai_api_key=OPENAI_API_KEY)\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/generative-ai/question-answering.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
}
],
"source": [
"!python3 -m pip install -qU langchain openai==0.28.1 elasticsearch tiktoken jq"
"!python3 -m pip install -qU langchain langchain-elasticsearch openai==0.28.1 tiktoken jq"
]
},
{
Expand Down Expand Up @@ -77,7 +77,7 @@
},
"outputs": [],
"source": [
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from langchain.embeddings.openai import OpenAIEmbeddings\n",
"from getpass import getpass\n",
"\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
"outputs": [],
"source": [
"# install packages\n",
"!python3 -m pip install -qU langchain elasticsearch boto3\n",
"!python3 -m pip install -qU langchain langchain-elasticsearch boto3\n",
"\n",
"# import modules\n",
"from getpass import getpass\n",
"from urllib.request import urlopen\n",
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from langchain.embeddings.bedrock import BedrockEmbeddings\n",
"from langchain.llms import Bedrock\n",
"from langchain.chains import RetrievalQA\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"metadata": {},
"outputs": [],
"source": [
"pip install -q -U google-generativeai elasticsearch langchain langchain_google_genai"
"pip install -q -U google-generativeai langchain-elasticsearch langchain langchain_google_genai"
]
},
{
Expand All @@ -60,8 +60,7 @@
"from getpass import getpass\n",
"from urllib.request import urlopen\n",
"\n",
"from elasticsearch import Elasticsearch, helpers\n",
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from langchain.text_splitter import CharacterTextSplitter\n",
"from langchain_google_genai import GoogleGenerativeAIEmbeddings\n",
"from langchain_google_genai import ChatGoogleGenerativeAI\n",
Expand Down
4 changes: 2 additions & 2 deletions notebooks/langchain/langchain-using-own-model.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@
"metadata": {},
"outputs": [],
"source": [
"!python3 -m pip install -qU langchain elasticsearch tiktoken sentence-transformers eland transformers\n",
"!python3 -m pip install -qU langchain langchain-elasticsearch tiktoken sentence-transformers eland transformers\n",
"\n",
"from getpass import getpass\n",
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from urllib.request import urlopen\n",
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
"import json"
Expand Down
4 changes: 2 additions & 2 deletions notebooks/langchain/langchain-vector-store-using-elser.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
"outputs": [],
"source": [
"# install packages\n",
"!python3 -m pip install -qU langchain openai elasticsearch tiktoken\n",
"!python3 -m pip install -qU langchain langchain-elasticsearch openai tiktoken\n",
"\n",
"# import modules\n",
"from getpass import getpass\n",
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from urllib.request import urlopen\n",
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
"import json"
Expand Down
4 changes: 2 additions & 2 deletions notebooks/langchain/langchain-vector-store.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@
"outputs": [],
"source": [
"# install packages\n",
"!python3 -m pip install -qU langchain openai elasticsearch tiktoken\n",
"!python3 -m pip install -qU langchain langchain-elasticsearch openai tiktoken\n",
"\n",
"# import modules\n",
"from getpass import getpass\n",
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from langchain.embeddings.openai import OpenAIEmbeddings\n",
"from urllib.request import urlopen\n",
"from langchain.text_splitter import RecursiveCharacterTextSplitter\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
}
],
"source": [
"!python3 -m pip install -qU jq lark elasticsearch langchain_openai tiktoken\n",
"!python3 -m pip install -qU jq lark langchain langchain-elasticsearch langchain_openai tiktoken\n",
"\n",
"from langchain_openai.embeddings import OpenAIEmbeddings\n",
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from langchain_openai.llms import OpenAI\n",
"from langchain.retrievers.multi_query import MultiQueryRetriever\n",
"from getpass import getpass"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
}
],
"source": [
"!python3 -m pip install -qU lark elasticsearch langchain_openai tiktoken\n",
"!python3 -m pip install -qU lark langchain langchain-elasticsearh langchain_openai tiktoken\n",
"\n",
"from langchain.schema import Document\n",
"from langchain_openai.embeddings import OpenAIEmbeddings\n",
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from langchain_openai.chat_models import ChatOpenAI\n",
"from langchain.retrievers.multi_query import MultiQueryRetriever\n",
"from getpass import getpass"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
}
],
"source": [
"!python3 -m pip install -qU lark elasticsearch langchain openai\n",
"!python3 -m pip install -qU lark elasticsearch langchain langchain-elasticsearch openai\n",
"\n",
"from langchain.schema import Document\n",
"from langchain.embeddings.openai import OpenAIEmbeddings\n",
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from langchain.llms import OpenAI\n",
"from langchain.retrievers.self_query.base import SelfQueryRetriever\n",
"from langchain.chains.query_constructor.base import AttributeInfo\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
}
],
"source": [
"!python3 -m pip install -qU lark elasticsearch langchain openai"
"!python3 -m pip install -qU lark elasticsearch langchain langchain-elasticsearch openai"
]
},
{
Expand Down Expand Up @@ -209,12 +209,11 @@
"metadata": {},
"outputs": [],
"source": [
"from langchain.vectorstores.elasticsearch import ApproxRetrievalStrategy\n",
"from typing import List, Union\n",
"from langchain.retrievers.self_query.base import SelfQueryRetriever\n",
"from langchain.chains.query_constructor.base import AttributeInfo\n",
"from langchain.llms import OpenAI\n",
"from langchain.vectorstores.elasticsearch import ElasticsearchStore\n",
"from langchain_elasticsearch import ApproxRetrievalStrategy, ElasticsearchStore\n",
"\n",
"# Add details about metadata fields\n",
"metadata_field_info = [\n",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@
}
],
"source": [
"!python3 -m pip install -qU lark elasticsearch langchain openai\n",
"!python3 -m pip install -qU lark langchain langchain-elasticsearch openai\n",
"\n",
"from langchain.schema import Document\n",
"from langchain.embeddings.openai import OpenAIEmbeddings\n",
"from langchain.vectorstores import ElasticsearchStore\n",
"from langchain_elasticsearch import ElasticsearchStore\n",
"from langchain.llms import OpenAI\n",
"from langchain.retrievers.self_query.base import SelfQueryRetriever\n",
"from langchain.chains.query_constructor.base import AttributeInfo\n",
Expand Down

0 comments on commit dfb9266

Please sign in to comment.