Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0a8f65f
add-tax
galshubeli Aug 18, 2025
3438c44
move-const-config
galshubeli Aug 18, 2025
b61598b
fix-bug
galshubeli Aug 18, 2025
05b70b0
fix-comments
galshubeli Aug 18, 2025
f6b2898
fix-bug
galshubeli Aug 18, 2025
e99998e
fix-tests
galshubeli Aug 18, 2025
4f6e6d5
single-func
galshubeli Aug 19, 2025
3d99fea
Update api/config.py
galshubeli Aug 19, 2025
94ede81
Merge branch 'main' into add-taxonomy
gkorland Aug 19, 2025
acaade4
gen-queries
galshubeli Aug 19, 2025
7cf175f
fix docker with fastapi
gkorland Aug 21, 2025
26b616a
Merge pull request #102 from FalkorDB/fix-docker
gkorland Aug 21, 2025
9fd9875
clean flask
gkorland Aug 21, 2025
5e9ba19
Merge branch 'main' into staging
gkorland Aug 21, 2025
101b012
Merge branch 'staging' into remove-flask
gkorland Aug 21, 2025
701db7f
Merge pull request #103 from FalkorDB/remove-flask
gkorland Aug 21, 2025
56b9c36
update deps
gkorland Aug 21, 2025
708de13
Merge branch 'staging' into deps
gkorland Aug 21, 2025
1b01b6a
Merge pull request #105 from FalkorDB/deps
gkorland Aug 21, 2025
e655e75
clean lint
gkorland Aug 21, 2025
9c2029c
fix lints
gkorland Aug 21, 2025
9d42263
clean lints
gkorland Aug 21, 2025
c279334
fix
gkorland Aug 21, 2025
890876a
fix tests
gkorland Aug 21, 2025
61897fe
fix tests
gkorland Aug 21, 2025
80d9315
fix tests
gkorland Aug 21, 2025
349f937
Merge pull request #106 from FalkorDB/lint-fixes
gkorland Aug 21, 2025
c0639c7
add design
gkorland Aug 21, 2025
5ce6dda
add header
gkorland Aug 21, 2025
d7141a1
Merge pull request #107 from FalkorDB/design
gkorland Aug 21, 2025
fe90292
add toolbar to mobile
gkorland Aug 22, 2025
d512568
set select size
gkorland Aug 22, 2025
f2fba00
Merge pull request #108 from FalkorDB/burgger
gkorland Aug 22, 2025
4d36bfa
Merge branch 'staging' into add-taxonomy
galshubeli Aug 24, 2025
9f7f3ae
rm-rw-condition
galshubeli Aug 24, 2025
fc0389d
rm-max-rw
galshubeli Aug 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions api/agents/taxonomy_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,15 @@
clarification in that way he have the relevent information to answer.
* When you ask the user to confirm a value, please provide the value in your answer.
* Mention only question about values and dont mention the SQL query or the tables in your answer.
* Use the explanation to understand what was unclear or ambiguous in the user's request.

** Understand what the SQL does and ask the user if this is what they need with a clarification question. **

Please create the clarification question step by step.

Last agent explanation:
{EXPLANATION}

Question:
{QUESTION}

Expand All @@ -42,11 +48,14 @@ class TaxonomyAgent:
def __init__(self):
"""Initialize the taxonomy agent."""

def get_answer(self, question: str, sql: str) -> str:
def get_answer(self, question: str, sql: str, explanation: str) -> str:
Comment thread
galshubeli marked this conversation as resolved.
"""Get taxonomy classification for a question and SQL pair."""
messages = [
{
"content": TAXONOMY_PROMPT.format(QUESTION=question, SQL=sql),
"content": TAXONOMY_PROMPT.format(QUESTION=question,
SQL=sql,
EXPLANATION=explanation.replace("{", "{{").replace("}", "}}")
),
"role": "user",
}
]
Expand Down
6 changes: 6 additions & 0 deletions api/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

"""
This module contains the configuration for the text2sql module.
"""



import dataclasses
from typing import Union

Expand Down Expand Up @@ -54,6 +57,9 @@ class Config:
COMPLETION_MODEL = "azure/gpt-4.1"
VALIDATOR_MODEL = "azure/gpt-4.1"
TEMPERATURE = 0
POSTGRES_MAX_ROWS: int = 500
POSTGRES_MAX_DISTINCT: int = 100
POSTGRES_UNIQUENESS_THRESHOLD: float = 0.5
# client = boto3.client('sts')
# AWS_PROFILE = os.getenv("aws_profile_name")
# AWS_REGION = os.getenv("aws_region_name")
Expand Down
34 changes: 33 additions & 1 deletion api/loaders/postgres_loader.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
"""PostgreSQL loader for loading database schemas into FalkorDB graphs."""

import re
import datetime
import decimal
import logging
import re
from api.config import Config
from typing import Tuple, Dict, Any, List

import psycopg2
Expand Down Expand Up @@ -233,6 +234,36 @@ def extract_columns_info(cursor, table_name: str) -> Dict[str, Any]:
if column_default:
description_parts.append(f"(Default: {column_default})")

# Count rows and distinct values for the column
cursor.execute(
f"""
SELECT COUNT(*) AS total_count,
COUNT(DISTINCT {col_name}) AS distinct_count
FROM {table_name};
"""
)
Comment thread
galshubeli marked this conversation as resolved.
output = cursor.fetchall()
rows_count, distinct_count = output[0]

Comment thread
galshubeli marked this conversation as resolved.
Outdated
max_rows = Config.POSTGRES_MAX_ROWS
max_distinct = Config.POSTGRES_MAX_DISTINCT
uniqueness_threshold = Config.POSTGRES_UNIQUENESS_THRESHOLD

if 0 < rows_count < max_rows and distinct_count < max_distinct:
uniqueness_value = distinct_count / rows_count
Comment thread
galshubeli marked this conversation as resolved.
Outdated
if uniqueness_value < uniqueness_threshold:
cursor.execute(
f"SELECT DISTINCT {col_name} FROM {table_name};"
Comment thread
galshubeli marked this conversation as resolved.
Outdated
)
distinct_values = [row[0] for row in cursor.fetchall() if row[0] is not None]
if distinct_values:
# Check first value type to avoid objects like dict/bytes
first_val = distinct_values[0]
if isinstance(first_val, (str, int, float)):
description_parts.append(
f"(Optional values: {', '.join(f'({str(v)})' for v in distinct_values)})"
)

columns_info[col_name] = {
'type': data_type,
'null': is_nullable,
Expand All @@ -241,6 +272,7 @@ def extract_columns_info(cursor, table_name: str) -> Dict[str, Any]:
'default': column_default
}


return columns_info

@staticmethod
Expand Down
17 changes: 13 additions & 4 deletions tests/test_postgres_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,19 @@ def test_extract_columns_info(self):
"""Test column information extraction"""
# Mock cursor with column data
mock_cursor = Mock()
mock_cursor.fetchall.return_value = [
("id", "integer", "NO", None, "PRIMARY KEY", "User ID"),
("name", "varchar", "NO", None, "NONE", "User name"),
("email", "varchar", "YES", None, "NONE", "User email address"),
mock_cursor.fetchall.side_effect = [
# First call: column metadata
[
("id", "integer", "NO", None, "PRIMARY KEY", "User ID"),
("name", "varchar", "NO", None, "NONE", "User name"),
("email", "varchar", "YES", None, "NONE", "User email address"),
],
# Second call: row count for 'id' column
[(100, 100)],
# Third call: row count for 'name' column
[(100, 50)],
# Fourth call: row count for 'email' column
[(100, 80)]
]

# Test the method
Expand Down