Concepts API

The Concepts API allows you to manage and execute Vadalog concepts within projects. This is one of the core APIs for working with logical reasoning and data analysis.

Save Concept

Save or update a concept with Vadalog logic and optional Python scripts.
import prometheux_chain as px

concept_def = """
company("Apple", "Redwood City, CA").
company("Google", "Mountain View, CA").
company("Microsoft", "Redmond, WA").

location(Location) <- company(_,Location).

@output("location").
"""

result = px.save_concept(
    project_id="my_project_id",
    definition=concept_def
)
Function Signature
def save_concept(project_id, definition, python_scripts=None, scope="user",
                 description=None, concept_type="logic", concept_name=None,
                 binds=None, output_predicate="", existing_name=None,
                 position=None, group="group_id", compute=None)
Parameters
ParameterTypeRequiredDescription
project_idstrYesThe project identifier
definitionstrYesThe Vadalog rules, SQL query, or Python logic defining the concept
python_scriptsdictNoDictionary of Python scripts to inject
scopestrNoThe scope of the concept. Defaults to "user"
descriptionstrNoHuman-readable description of the concept
concept_typestrNo"logic" or "sql". Defaults to "logic"
concept_namestrConditionalRequired for SQL concepts

Python Script Injection Requirements

When using Python script injection with save_concept, there are specific requirements:

1. Main Function Requirement

Every Python script must contain a main() function:
def main():
    # Your script logic here
    return results

2. Tabular Output Format

The main() function must return results as a list of dictionaries:
def main():
    results = [{"Column1": value1, "Column2": value2}]
    return results

3. Concept Head Alignment

Output column names must match the parameters in the concept head:
# Python script returns:
results = [{"Numbers": [1, 2, 3], "Total": 6, "Average": 2.0}]

# Vadalog concept head must match:
test_python(Numbers, Total, Average) <- python:run("python_script").

4. Standalone Concept Rule

Python script concepts must be standalone:
# Correct - standalone Python script concept
@output("my_python_concept").
my_python_concept(Col1, Col2) <- python:run("my_script").

# Incorrect - cannot combine with other logic
@output("mixed_concept").
mixed_concept(Col1, Col2) <- python:run("my_script"), other_predicate(Col1).

Run Concept

Execute a concept with specified parameters.
import prometheux_chain as px

results = px.run_concept(
    project_id="my_project_id",
    concept_name="location",
    params={"filter_city": "CA"},
    persist_outputs=True
)
Function Signature
def run_concept(project_id, concept_name, params=None, scope="user",
                force_rerun=True, persist_outputs=False, compute=None)
Parameters
ParameterTypeRequiredDescription
project_idstrYesThe project identifier
concept_namestrYesThe name of the concept to run
paramsdictNoParameters to pass to the concept execution
scopestrNoThe scope of the project. Defaults to "user"
force_rerunboolNoForce rerun even if results exist. Defaults to True
persist_outputsboolNoPersist the outputs. Defaults to False

Fetch Results

Paginated fetch of stored results for an output predicate.
import prometheux_chain as px

rows = px.fetch_results(
    project_id="my_project_id",
    output_predicate="location",
    page=1,
    page_size=10,
    scope="user",
)

List Concepts

List all concepts in a project.
import prometheux_chain as px

concepts = px.list_concepts(project_id="my_project_id")
print(f"Available concepts: {concepts}")

Cleanup Concepts

Delete concepts from a project.
import prometheux_chain as px

# Clean up all concepts in a project
result = px.cleanup_concepts(project_id="my_project_id")

# Clean up specific concepts by name
result = px.cleanup_concepts(
    project_id="my_project_id",
    concept_names=["ordered_bom", "product_analysis"],
)