Skip to content

Commit c1584fc

Browse files
committed
LLM: Update to langchain-cratedb 0.0.0
After quite a bit of back and forth, and a slow genesis in general, this subsystem is finally approaching departures to take off. On the chrome/surface/interface, this update doesn't change much, just a few bits of "naming things".
1 parent 706a09d commit c1584fc

12 files changed

+58
-89
lines changed

topic/machine-learning/llm-langchain/conversational_memory.ipynb

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,18 @@
5959
"execution_count": 2,
6060
"outputs": [],
6161
"source": [
62-
"from langchain_community.chat_message_histories import CrateDBChatMessageHistory\n",
62+
"from langchain_cratedb.chat_history import CrateDBChatMessageHistory\n",
6363
"\n",
6464
"# Connect to a self-managed CrateDB instance.\n",
6565
"CONNECTION_STRING = \"crate://crate@localhost/?schema=notebook\"\n",
6666
"\n",
67-
"chat_message_history = CrateDBChatMessageHistory(\n",
67+
"chat_history = CrateDBChatMessageHistory(\n",
6868
"\tsession_id=\"test_session\",\n",
6969
"\tconnection_string=CONNECTION_STRING\n",
7070
")\n",
7171
"\n",
7272
"# Make sure to start with a blank canvas.\n",
73-
"chat_message_history.clear()"
73+
"chat_history.clear()"
7474
],
7575
"metadata": {
7676
"collapsed": false
@@ -90,8 +90,8 @@
9090
"execution_count": 3,
9191
"outputs": [],
9292
"source": [
93-
"chat_message_history.add_user_message(\"Hello\")\n",
94-
"chat_message_history.add_ai_message(\"Hi\")"
93+
"chat_history.add_user_message(\"Hello\")\n",
94+
"chat_history.add_ai_message(\"Hi\")"
9595
],
9696
"metadata": {
9797
"collapsed": false,
@@ -117,9 +117,7 @@
117117
"output_type": "execute_result"
118118
}
119119
],
120-
"source": [
121-
"chat_message_history.messages"
122-
],
120+
"source": "chat_history.messages",
123121
"metadata": {
124122
"collapsed": false,
125123
"ExecuteTime": {
@@ -214,7 +212,7 @@
214212
"\n",
215213
"\tBase.metadata.drop_all(bind=sa.create_engine(CONNECTION_STRING))\n",
216214
"\n",
217-
"\tchat_message_history = CrateDBChatMessageHistory(\n",
215+
"\tchat_history = CrateDBChatMessageHistory(\n",
218216
"\t\tsession_id=\"test_session\",\n",
219217
"\t\tconnection_string=CONNECTION_STRING,\n",
220218
"\t\tcustom_message_converter=CustomMessageConverter(\n",
@@ -223,10 +221,10 @@
223221
"\t)\n",
224222
"\n",
225223
"\t# Make sure to start with a blank canvas.\n",
226-
"\tchat_message_history.clear()\n",
224+
"\tchat_history.clear()\n",
227225
"\n",
228-
"\tchat_message_history.add_user_message(\"Hello\")\n",
229-
"\tchat_message_history.add_ai_message(\"Hi\")"
226+
"\tchat_history.add_user_message(\"Hello\")\n",
227+
"\tchat_history.add_ai_message(\"Hi\")"
230228
],
231229
"metadata": {
232230
"collapsed": false,
@@ -252,9 +250,7 @@
252250
"output_type": "execute_result"
253251
}
254252
],
255-
"source": [
256-
"chat_message_history.messages"
257-
],
253+
"source": "chat_history.messages",
258254
"metadata": {
259255
"collapsed": false,
260256
"ExecuteTime": {
@@ -286,7 +282,7 @@
286282
"import json\n",
287283
"import typing as t\n",
288284
"\n",
289-
"from langchain_community.chat_message_histories.cratedb import CrateDBMessageConverter\n",
285+
"from langchain_cratedb.chat_history import CrateDBMessageConverter\n",
290286
"from langchain.schema import _message_to_dict\n",
291287
"\n",
292288
"\n",
@@ -312,18 +308,18 @@
312308
"if __name__ == \"__main__\":\n",
313309
"\tBase.metadata.drop_all(bind=sa.create_engine(CONNECTION_STRING))\n",
314310
"\n",
315-
"\tchat_message_history = CrateDBChatMessageHistory(\n",
311+
"\tchat_history = CrateDBChatMessageHistory(\n",
316312
"\t\tsession_id=\"test_session\",\n",
317313
"\t\tconnection_string=CONNECTION_STRING,\n",
318314
"\t\tcustom_message_converter=CustomMessageConverterWithDifferentSessionIdColumn(),\n",
319315
"\t\tsession_id_field_name=\"custom_session_id\",\n",
320316
"\t)\n",
321317
"\n",
322318
"\t# Make sure to start with a blank canvas.\n",
323-
"\tchat_message_history.clear()\n",
319+
"\tchat_history.clear()\n",
324320
"\n",
325-
"\tchat_message_history.add_user_message(\"Hello\")\n",
326-
"\tchat_message_history.add_ai_message(\"Hi\")"
321+
"\tchat_history.add_user_message(\"Hello\")\n",
322+
"\tchat_history.add_ai_message(\"Hi\")"
327323
],
328324
"metadata": {
329325
"collapsed": false
@@ -344,9 +340,7 @@
344340
"output_type": "execute_result"
345341
}
346342
],
347-
"source": [
348-
"chat_message_history.messages"
349-
],
343+
"source": "chat_history.messages",
350344
"metadata": {
351345
"collapsed": false
352346
}

topic/machine-learning/llm-langchain/conversational_memory.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
import os
1717
from pprint import pprint
1818

19-
from langchain_community.chat_message_histories import CrateDBChatMessageHistory
19+
from langchain_cratedb.chat_history import CrateDBChatMessageHistory
2020

2121

2222
CONNECTION_STRING = os.environ.get(
@@ -27,13 +27,13 @@
2727

2828
def main():
2929

30-
chat_message_history = CrateDBChatMessageHistory(
30+
chat_history = CrateDBChatMessageHistory(
3131
session_id="test_session",
32-
connection_string=CONNECTION_STRING,
32+
connection=CONNECTION_STRING,
3333
)
34-
chat_message_history.add_user_message("Hello")
35-
chat_message_history.add_ai_message("Hi")
36-
pprint(chat_message_history.messages)
34+
chat_history.add_user_message("Hello")
35+
chat_history.add_ai_message("Hi")
36+
pprint(chat_history.messages)
3737

3838

3939
if __name__ == "__main__":

topic/machine-learning/llm-langchain/cratedb-vectorstore-rag-openai-sql.ipynb

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,11 @@
7575
"metadata": {},
7676
"outputs": [],
7777
"source": [
78-
"import openai\n",
7978
"import pandas as pd\n",
8079
"import sqlalchemy as sa\n",
8180
"\n",
8281
"from langchain_community.document_loaders import PyPDFLoader\n",
83-
"from langchain_text_splitters import RecursiveCharacterTextSplitter\n",
84-
"from langchain_openai import OpenAIEmbeddings"
82+
"from langchain_text_splitters import RecursiveCharacterTextSplitter"
8583
]
8684
},
8785
{
@@ -162,7 +160,7 @@
162160
"# environment variables.\n",
163161
"import os\n",
164162
"\n",
165-
"CONNECTION_STRING = CrateDBVectorSearch.connection_string_from_db_params(\n",
163+
"CONNECTION_STRING = CrateDBVectorStore.connection_string_from_db_params(\n",
166164
" driver=os.environ.get(\"CRATEDB_DRIVER\", \"crate\"),\n",
167165
" host=os.environ.get(\"CRATEDB_HOST\", \"localhost\"),\n",
168166
" port=int(os.environ.get(\"CRATEDB_PORT\", \"4200\")),\n",

topic/machine-learning/llm-langchain/cratedb_rag_customer_support.ipynb

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,15 @@
6565
},
6666
"outputs": [],
6767
"source": [
68-
"from langchain.chains import RetrievalQA, ConversationalRetrievalChain\n",
69-
"from langchain_openai import ChatOpenAI, OpenAI, OpenAIEmbeddings\n",
70-
"import pandas as pd\n",
71-
"import sqlalchemy as sa\n",
72-
"from sqlalchemy import create_engine\n",
73-
"from sqlalchemy import text\n",
74-
"import crate\n",
7568
"import openai\n",
76-
"import os\n",
7769
"import requests\n",
78-
"from pueblo.util.environ import getenvpass\n",
70+
"import pandas as pd\n",
71+
"from langchain.chains import RetrievalQA, ConversationalRetrievalChain\n",
7972
"from langchain_community.document_loaders import CSVLoader\n",
80-
"from langchain_community.vectorstores import Chroma\n",
81-
"from langchain_text_splitters import RecursiveCharacterTextSplitter"
73+
"from langchain_openai import OpenAIEmbeddings\n",
74+
"from pueblo.util.environ import getenvpass\n",
75+
"from sqlalchemy import create_engine\n",
76+
"from sqlalchemy import text"
8277
]
8378
},
8479
{

topic/machine-learning/llm-langchain/cratedb_rag_customer_support_langchain.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@
107107
"from pueblo.util.environ import getenvpass\n",
108108
"from langchain_openai import OpenAIEmbeddings\n",
109109
"from langchain_community.document_loaders import CSVLoader\n",
110-
"from langchain_community.vectorstores import CrateDBVectorSearch\n",
110+
"from langchain_cratedb.vectorstores import CrateDBVectorStore\n",
111111
"\n",
112112
"warnings.filterwarnings('ignore')"
113113
]
@@ -301,11 +301,11 @@
301301
"source": [
302302
"embeddings = OpenAIEmbeddings()\n",
303303
"\n",
304-
"store = CrateDBVectorSearch.from_documents(\n",
304+
"store = CrateDBVectorStore.from_documents(\n",
305305
" embedding=embeddings,\n",
306306
" documents=data,\n",
307307
" collection_name=COLLECTION_NAME,\n",
308-
" connection_string=CONNECTION_STRING,\n",
308+
" connection=CONNECTION_STRING,\n",
309309
")"
310310
]
311311
},
@@ -519,11 +519,11 @@
519519
"\n",
520520
"COLLECTION_NAME = \"customer_data_jina\"\n",
521521
"\n",
522-
"store = CrateDBVectorSearch.from_documents(\n",
522+
"store = CrateDBVectorStore.from_documents(\n",
523523
" embedding=embeddings,\n",
524524
" documents=data,\n",
525525
" collection_name=COLLECTION_NAME,\n",
526-
" connection_string=CONNECTION_STRING,\n",
526+
" connection=CONNECTION_STRING,\n",
527527
")\n",
528528
"documents = return_documents(store, my_question)"
529529
]

topic/machine-learning/llm-langchain/cratedb_rag_customer_support_vertexai.ipynb

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -97,28 +97,20 @@
9797
"outputs": [],
9898
"source": [
9999
"import os\n",
100+
"import re\n",
100101
"\n",
101-
"import openai\n",
102102
"import pandas as pd\n",
103-
"import warnings\n",
104103
"import requests\n",
105-
"import re\n",
106-
"from typing import Dict, List, Optional, Tuple, Union\n",
107-
"\n",
104+
"import warnings\n",
108105
"\n",
109-
"from pueblo.util.environ import getenvpass\n",
110106
"from google.cloud import aiplatform\n",
111107
"from vertexai.generative_models import (\n",
112108
" GenerationConfig,\n",
113-
" GenerationResponse,\n",
114109
" GenerativeModel,\n",
115-
" HarmBlockThreshold,\n",
116-
" HarmCategory,\n",
117110
")\n",
118111
"from langchain_community.document_loaders import CSVLoader\n",
119112
"from langchain_community.embeddings import VertexAIEmbeddings\n",
120-
"from langchain_community.llms import VertexAI\n",
121-
"from langchain_community.vectorstores import CrateDBVectorSearch\n",
113+
"from langchain_cratedb.vectorstores import CrateDBVectorStore\n",
122114
"\n",
123115
"warnings.filterwarnings('ignore')"
124116
]
@@ -347,11 +339,11 @@
347339
"source": [
348340
"embeddings = VertexAIEmbeddings(model_name=\"textembedding-gecko@001\")\n",
349341
"\n",
350-
"store = CrateDBVectorSearch.from_documents(\n",
342+
"store = CrateDBVectorStore.from_documents(\n",
351343
" embedding=embeddings,\n",
352344
" documents=data,\n",
353345
" collection_name=COLLECTION_NAME,\n",
354-
" connection_string=CONNECTION_STRING,\n",
346+
" connection=CONNECTION_STRING,\n",
355347
")"
356348
]
357349
},

topic/machine-learning/llm-langchain/document_loader.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@
107107
"outputs": [],
108108
"source": [
109109
"import sqlalchemy as sa\n",
110-
"from langchain_community.document_loaders import CrateDBLoader\n",
111110
"from langchain_community.utilities.sql_database import SQLDatabase\n",
111+
"from langchain_cratedb.loaders import CrateDBLoader\n",
112112
"from pprint import pprint\n",
113113
"\n",
114114
"db = SQLDatabase(engine=sa.create_engine(CONNECTION_STRING))\n",

topic/machine-learning/llm-langchain/document_loader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import requests
3030
import sqlalchemy as sa
3131
from cratedb_toolkit.util import DatabaseAdapter
32-
from langchain_community.document_loaders import CrateDBLoader
3332
from langchain_community.utilities.sql_database import SQLDatabase
33+
from langchain_cratedb.loaders import CrateDBLoader
3434
from pprint import pprint
3535

3636

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
# Real.
1+
# Production.
22
cratedb-toolkit[io]
33
pueblo[notebook,testing]
44

5-
# Development.
5+
# Staging.
66
# cratedb-toolkit[io] @ git+https://github.com/crate-workbench/cratedb-toolkit.git@main
77
# pueblo[notebook,testing] @ git+https://github.com/pyveci/pueblo.git@main
88

9-
# Workstation.
9+
# Development.
1010
#--editable=/Users/amo/dev/crate/ecosystem/cratedb-retentions[io]
1111
#--editable=/Users/amo/dev/pyveci/sources/pueblo[testing]
Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,12 @@
1-
# Real.
21
crash
3-
crate>=1.0.0.dev2
42
google-cloud-aiplatform<2
3+
langchain-cratedb>=0.0.0.dev0
54
langchain-google-vertexai<3
65
langchain-openai<0.3
76
langchain-text-splitters<0.4
87
pueblo[cli,nlp]>=0.0.10
9-
pydantic>=2,<3
108
pypdf<6
119
python-dotenv<2
1210
requests<3
1311
requests-cache<2
14-
sqlalchemy==2.*
15-
sqlalchemy-cratedb>=0.40.0
1612
unstructured<0.17
17-
18-
# Development.
19-
# cratedb-toolkit @ git+https://github.com/crate-workbench/cratedb-toolkit.git@main
20-
langchain @ git+https://github.com/crate-workbench/langchain.git@cratedb#subdirectory=libs/langchain
21-
langchain-community @ git+https://github.com/crate-workbench/langchain.git@cratedb#subdirectory=libs/community
22-
# pueblo[cli,fileio,nlp] @ git+https://github.com/pyveci/pueblo.git@main

0 commit comments

Comments
 (0)