@@ -58,6 +58,9 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
58
58
from langchain .chains import create _retrieval _chain
59
59
from langchain .chains .combine _documents import create _stuff _documents _chain
60
60
61
+ import os
62
+ from sqlalchemy import text
63
+
61
64
try :
62
65
loader = CSVLoader (file _path ='/home /irisowner /dev /src /data /synthetic _data _01 .csv ')
63
66
docs = loader .load ()
@@ -67,20 +70,27 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
67
70
llm = ChatOpenAI (model = model , temperature =0 , api _key =apiKey )
68
71
embeddings = OpenAIEmbeddings (openai _api _key =apiKey )
69
72
70
- # call IRISVector passing a list of documents to be stored in a collection
71
- #; vectorstore = IRISVector.from_documents(
72
- #; documents=splits,
73
- #; embedding=OpenAIEmbeddings(openai_api_key=apiKey),
74
- #; dimension=1536,
75
- #; collection_name=collectionName,
76
- #; )
77
-
78
73
# call IRISVector using a previous collection
79
74
vectorstore = IRISVector (
80
75
embedding _function =OpenAIEmbeddings (openai _api _key =apiKey ),
81
76
dimension =1536 ,
82
77
collection _name =collectionName ,
83
78
)
79
+ # check if document collection exists
80
+ conn = vectorstore .connect ()
81
+ #; sql = f"select count(*) from INFORMATION_SCHEMA.TABLES where TABLE_SCHEMA = 'SQLUser' and TABLE_NAME = 'mediCopilot-docs'"
82
+ sql = f 'SELECT count (*) FROM SQLUser ." mediCopilot-docs" '
83
+ result = conn .execute (text (sql ))
84
+ collection _exists = result .first ()[0 ] > 0
85
+ print (collection _exists )
86
+ if not collection _exists :
87
+ # call IRISVector passing a list of documents to be stored in a collection
88
+ vectorstore = IRISVector .from _documents (
89
+ documents =splits ,
90
+ embedding =OpenAIEmbeddings (openai _api _key =apiKey ),
91
+ dimension =1536 ,
92
+ collection _name =collectionName ,
93
+ )
84
94
85
95
retriever = vectorstore .as _retriever ()
86
96
@@ -133,7 +143,8 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
133
143
)
134
144
135
145
ai _msg _1 = conversational _rag _chain .invoke (
136
- {" input" : " What is Task Decomposition?" },
146
+ #; {"input": "What is Task Decomposition?"},
147
+ {" input" : question },
137
148
config ={
138
149
" configurable" : {" session_id" : sessionId }
139
150
},
0 commit comments