v0.7.4-add_vector_search #33
+5
-5
@@ -2,7 +2,7 @@
|
||||
|
||||
julia_version = "1.12.6"
|
||||
manifest_format = "2.0"
|
||||
project_hash = "dc7878808bbc4637a12e709dd495979a784824a5"
|
||||
project_hash = "fec141f7ff95c7150e820def295f9929445168b6"
|
||||
|
||||
[[deps.Accessors]]
|
||||
deps = ["CompositionsBase", "ConstructionBase", "Dates", "InverseFunctions", "MacroTools"]
|
||||
@@ -300,11 +300,11 @@ version = "1.1.0"
|
||||
|
||||
[[deps.GeneralUtils]]
|
||||
deps = ["CSV", "DataFrames", "DataStructures", "Dates", "Distributions", "Graphs", "HTTP", "JSON", "LibPQ", "NATS", "PrettyPrinting", "Random", "Revise", "SHA", "StringDistances", "UUIDs"]
|
||||
git-tree-sha1 = "a75a088ee8e5faf10f554ca00748e0e6ca58d1ca"
|
||||
git-tree-sha1 = "596da266c851d00fbabcf33660419aeffb820fcb"
|
||||
repo-rev = "main"
|
||||
repo-url = "https://git.yiem.cc/ton/GeneralUtils"
|
||||
uuid = "c6c72f09-b708-4ac8-ac7c-2084d70108fe"
|
||||
version = "0.5.1"
|
||||
version = "0.5.7"
|
||||
|
||||
[[deps.Graphs]]
|
||||
deps = ["ArnoldiMethod", "DataStructures", "Inflate", "LinearAlgebra", "Random", "SimpleTraits", "SparseArrays", "Statistics"]
|
||||
@@ -1089,10 +1089,10 @@ uuid = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
|
||||
version = "0.4.16"
|
||||
|
||||
[[deps.YiemAgent]]
|
||||
deps = ["Base64", "CSV", "DataFrames", "DataStructures", "Dates", "GeneralUtils", "HTTP", "JSON", "LLMMCTS", "LibPQ", "NATS", "PrettyPrinting", "Random", "Revise", "SQLLLM", "Serialization", "URIs", "UUIDs"]
|
||||
deps = ["Base64", "CSV", "DataFrames", "DataStructures", "Dates", "HTTP", "JSON", "LLMMCTS", "LibPQ", "NATS", "PrettyPrinting", "Random", "Revise", "SQLLLM", "Serde", "Serialization", "URIs", "UUIDs"]
|
||||
path = "."
|
||||
uuid = "e012c34b-7f78-48e0-971c-7abb83b6f0a2"
|
||||
version = "0.7.2"
|
||||
version = "0.7.4"
|
||||
|
||||
[[deps.Zlib_jll]]
|
||||
deps = ["Libdl"]
|
||||
|
||||
+1
-1
@@ -28,7 +28,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
|
||||
Base64 = "1.11.0"
|
||||
CSV = "0.10.15"
|
||||
DataFrames = "1.7.0"
|
||||
GeneralUtils = "0.5.1"
|
||||
GeneralUtils = "0.5.7"
|
||||
HTTP = "2.4.0"
|
||||
JSON = "1.6.1"
|
||||
LLMMCTS = "0.1.5"
|
||||
|
||||
+16
-15
@@ -302,10 +302,16 @@ function search_wine_database!(a::T, thoughtdict::AbstractDict; useSQLLLM::Bool=
|
||||
else
|
||||
|
||||
# direct query with possible sql instead of SQLLLM.
|
||||
sql = predefined_wine_search_sql(a, thoughtdict["action_input"])
|
||||
hard_conditions, vector_search_words = wine_search_term_classification(a, thoughtdict["action_input"])
|
||||
|
||||
# do hard filter
|
||||
# sql = generatesql(a, inventoryquery)
|
||||
println("\nSQL: $sql ", @__FILE__, ":", @__LINE__, " $(Dates.now()) \n")
|
||||
sql = predefined_wine_search_sql(hard_conditions)
|
||||
@info "\nsql: $sql, \nvector_search_words: $vector_search_words"
|
||||
textresult, sql_result_df, success, _ = SQLexecution(a.context.executeSQL, sql)
|
||||
|
||||
#WORKING do vector search
|
||||
GeneralUtils.find_text_vector_similarity(vector_search_words, "wine")
|
||||
|
||||
items = nothing
|
||||
if sql_result_df !== nothing
|
||||
@@ -619,9 +625,9 @@ julia> thoughtdict =
|
||||
```
|
||||
julia> predefined_wine_search_sql(agent, thoughtdict["action_input"])
|
||||
"""
|
||||
function predefined_wine_search_sql(a::T, searchterm::String,
|
||||
function wine_search_term_classification(a::T, searchterm::String,
|
||||
; maxattempt=10
|
||||
)::String where {T<:agent}
|
||||
) where {T<:agent}
|
||||
|
||||
systemmsg =
|
||||
"""
|
||||
@@ -641,7 +647,7 @@ function predefined_wine_search_sql(a::T, searchterm::String,
|
||||
The "extracted_info" key must contain an array of objects. Each object must contain:
|
||||
1) "table_name": The name of the table.
|
||||
2) "column_name": The specific column being filtered.
|
||||
3) "operator": The comparison operator (e.g., "=", ">", "LIKE").
|
||||
3) "operator": The comparison operator (e.g., "=", ">").
|
||||
4) "value": The value to compare against.
|
||||
|
||||
If the user does not specify any filters, return an empty array for "extracted_info": {"extracted_info": []}.
|
||||
@@ -668,7 +674,7 @@ function predefined_wine_search_sql(a::T, searchterm::String,
|
||||
{
|
||||
"table_name": "car_info",
|
||||
"column_name": "drive_feeling",
|
||||
"operator": "ILIKE",
|
||||
"operator": "=",
|
||||
"value": "fast and furious"
|
||||
},
|
||||
{
|
||||
@@ -781,7 +787,7 @@ function predefined_wine_search_sql(a::T, searchterm::String,
|
||||
println("\n ", responsedict)
|
||||
@info "before BM25 " @__LINE__
|
||||
|
||||
#WORKING to ensure user input is correct
|
||||
# to ensure user input is correct
|
||||
for entry in responsedict["extracted_info"]
|
||||
table_name = entry["table_name"]::String
|
||||
column_name = entry["column_name"]::String
|
||||
@@ -802,11 +808,12 @@ function predefined_wine_search_sql(a::T, searchterm::String,
|
||||
|
||||
# Build new list of hard condition entries
|
||||
hard_conditions = JSON.Object{String, Any}[]
|
||||
vector_search = JSON.Object{String, Any}[]
|
||||
for entry in responsedict["extracted_info"]
|
||||
if entry["operator"] ∈ hard_operators
|
||||
push!(hard_conditions, entry)
|
||||
else
|
||||
vector_search_words = vector_search_words * entry["value"] * ", "
|
||||
push!(vector_search, entry)
|
||||
end
|
||||
end
|
||||
responsedict = hard_conditions
|
||||
@@ -814,14 +821,8 @@ function predefined_wine_search_sql(a::T, searchterm::String,
|
||||
println("")
|
||||
@show responsedict
|
||||
@info "predefined_wine_search_sql() " @__LINE__
|
||||
|
||||
#WORKING do vector search
|
||||
println("")
|
||||
@show vector_search_words
|
||||
# error(9999)
|
||||
sql = predefined_wine_search_sql(responsedict)
|
||||
|
||||
return sql
|
||||
return (hard_conditions=hard_conditions, vector_search=vector_search)
|
||||
end
|
||||
error("SQLLLM DecisionMaker() failed to generate a thought \n", response)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user