Merged Documentation¶
Documentation for get_cast_type
¶
Functionality¶
Determines the appropriate SQLAlchemy type based on the Python value. It returns types such as Text, Integer, or Float, ensuring correct casting for SQL queries.
Parameters¶
value
: A Python value used to determine its corresponding SQLAlchemy type.
Usage¶
- Purpose: Identify the SQLAlchemy type for proper data casting in database queries.
Example¶
For instance, if you pass an integer value:
>>> get_cast_type(42)
<class 'sqlalchemy.sql.sqltypes.Integer'>
Documentation for group_values_by_type
¶
Functionality¶
This function groups a list of values based on their derived SQLAlchemy types. It uses a helper to detect each value's type (e.g., Text, Integer, or Float) and returns a dictionary where keys are types and values are lists of the original values.
Parameters¶
values
: A list of Python values to be grouped.
Returns¶
- A dictionary mapping SQLAlchemy types to lists of values.
Usage¶
Use the function to separate values for SQL queries based on their types, which simplifies building type-specific query parts.
Example¶
Given a list like:
[ 'hello', 100, 'world', 3.14, 200 ]
the function returns a mapping where text and numeric values are grouped separately.
Documentation for translate_query_to_orm_filters
¶
Functionality¶
This function converts a PayloadFilter object into SQLAlchemy filter conditions. It handles both JSON-based queries and raw column queries by producing two lists of filters: one for combined conditions and one for specialized cases.
Parameters¶
payload_filter
: A PayloadFilter object to be translated.prefix
: A prefix string for JSON field references (default: "payload").language
: The language setting for text search operations (default: "simple").
Usage¶
- Purpose: Convert a PayloadFilter into SQLAlchemy ORM filter conditions, useful in query construction.
Example¶
from embedding_studio.vectordb.pgvector.query_to_sql import translate_query_to_orm_filters
from embedding_studio.models.payload.models import PayloadFilter
# Create and set up a PayloadFilter object
payload_filter = PayloadFilter(...)
# Translate filter object into SQLAlchemy conditions
filters, solid_filters = translate_query_to_orm_filters(payload_filter)
Documentation for translate_query_to_sql_filters
¶
Functionality¶
This function converts a PayloadFilter object into SQLAlchemy filter conditions usable in ORM queries. It handles several types of queries and returns two lists of conditions for combining or specialized contexts.
Parameters¶
payload_filter
: A PayloadFilter object containing query details.prefix
: A string prefix for JSON field references (default is "payload").language
: Search language for text operations (default is "simple").
Usage¶
- Purpose: Convert high-level query objects into SQLAlchemy filters for queries.
Example¶
from embedding_studio.vectordb.pgvector.query_to_sql import translate_query_to_sql_filters
filters, solid_filters = translate_query_to_sql_filters(payload_filter)