This commit is contained in:
2026-07-14 13:00:39 +07:00
parent f28405f3f1
commit a15630619a
3 changed files with 237 additions and 52 deletions
+24 -18
View File
@@ -4,8 +4,8 @@ export formatLLMtext, extractthink, checkAgentResponse_JSON, clean_json_response
extract_vector_metadata, generate_embedding_payloads, resolve_semantic_cluster,
harvest_entity_catalog, resolve_entity
using UUIDs, JSON, Dates, DataFrames, StringDistances, Graphs
using GeneralUtils
using UUIDs, JSON, Dates, DataFrames, StringDistances, Graphs, LibPQ
using ..util
# ---------------------------------------------- 100 --------------------------------------------- #
@@ -294,7 +294,7 @@ function extract_vector_metadata(pg_conn_str::String)::DataFrame
try
# Execute and format into a clean DataFrame
result = execute(conn, query)
result = LibPQ.execute(conn, query)
df = DataFrame(result)
# Create a unique document ID for each vector row
@@ -532,18 +532,24 @@ julia> fruits = GeneralUtils.harvest_entity_catalog(conn, "products", "fruit_nam
```
"""
function harvest_entity_catalog(conn_str::String, table::String, column::String)::Vector{String}
conn = LibPQ.Connection(conn_str)
# We only care about unique, non-null values to keep the index fast and dense
query = "SELECT DISTINCT $(column) FROM $(table) WHERE $(column) IS NOT NULL;"
try
df = DataFrame(execute(conn, query))
# Return as a clean array of strings
return String.(strip.(df[:, 1]))
finally
close(conn)
end
conn = LibPQ.Connection(conn_str)
return harvest_entity_catalog(conn, table, column)
end
function harvest_entity_catalog(conn, table::String, column::String)::Vector{String}
# We only care about unique, non-null values to keep the index fast and dense
query = "SELECT DISTINCT $(column) FROM $(table) WHERE $(column) IS NOT NULL;"
try
df = DataFrame(LibPQ.execute(conn, query))
# Return as a clean array of strings
return String.(strip.(df[:, 1]))
catch
return String[]
finally
close(conn)
end
end
@@ -580,13 +586,13 @@ The function:
```julia
julia> using GeneralUtils
julia> catalog = ["Hand Old Bar & Grill", "Hand Old", "Wine Cellar"]
julia> GeneralUtils.resolve_entity("HandOld", catalog, threshold=0.5)
julia> GeneralUtils.resolve_entity("HandOld", catalog; threshold=0.5)
"Hand Old Bar & Grill"
julia> GeneralUtils.resolve_entity("Wine Cellar", catalog, threshold=0.5)
julia> GeneralUtils.resolve_entity("Wine Cellar", catalog; threshold=0.5)
"Wine Cellar"
julia> GeneralUtils.resolve_entity("Unknown Place", catalog, threshold=0.5)
julia> GeneralUtils.resolve_entity("Unknown Place", catalog; threshold=0.5)
""
```
"""