Skip to content

Commit bf8cef2

Browse files
committed
fix on loading data only in once; fix to send the user question to the llm
1 parent 0374bc3 commit bf8cef2

File tree

3 files changed

+25
-12
lines changed

3 files changed

+25
-12
lines changed

iris.script

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525

2626
zpm "load /home/irisowner/dev/ -v":1:1
2727

28-
Write "Loading docs...", !
29-
Do ##class(dc.irisMediCopilot.util.Setup).LoadDocsToVectorSearch()
30-
Write "done!",!
28+
//Write "Loading docs...", !
29+
//Do ##class(dc.irisMediCopilot.util.Setup).LoadDocsToVectorSearch()
30+
//Write "done!",!
3131

3232
halt

src/dc/irisMediCopilot/core/MediCopilot.cls

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
5858
from langchain.chains import create_retrieval_chain
5959
from langchain.chains.combine_documents import create_stuff_documents_chain
6060

61+
import os
62+
from sqlalchemy import text
63+
6164
try:
6265
loader = CSVLoader(file_path='/home/irisowner/dev/src/data/synthetic_data_01.csv')
6366
docs = loader.load()
@@ -67,20 +70,27 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
6770
llm = ChatOpenAI(model= model, temperature=0, api_key=apiKey)
6871
embeddings = OpenAIEmbeddings(openai_api_key=apiKey)
6972

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-
7873
# call IRISVector using a previous collection
7974
vectorstore = IRISVector(
8075
embedding_function=OpenAIEmbeddings(openai_api_key=apiKey),
8176
dimension=1536,
8277
collection_name=collectionName,
8378
)
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+
)
8494

8595
retriever = vectorstore.as_retriever()
8696

@@ -133,7 +143,8 @@ ClassMethod RetrieveAnswer(apiKey As %String, collectionName As %String, questio
133143
)
134144

135145
ai_msg_1 = conversational_rag_chain.invoke(
136-
{"input": "What is Task Decomposition?"},
146+
#; {"input": "What is Task Decomposition?"},
147+
{"input": question},
137148
config={
138149
"configurable": {"session_id": sessionId}
139150
},

src/dc/irisMediCopilot/util/Setup.cls

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ ClassMethod Init(Token As %String = "", OpenAIKey As %String = "") As %Status
2424
Do ##class(%EnsembleMgr).SetAutoStart($namespace, ..#PRODUCTION)
2525
Job ##class(Ens.Director).StartProduction(..#PRODUCTION)
2626

27+
#; Do ##class(dc.irisMediCopilot.util.Setup).LoadDocsToVectorSearch()
28+
2729
Return sc
2830
}
2931

0 commit comments

Comments
 (0)