mirror of
https://github.com/hwchase17/langchain.git
synced 2025-09-22 19:09:57 +00:00
docs: query analysis use case (#17766)
Co-authored-by: Harrison Chase <hw.chase.17@gmail.com>
This commit is contained in:
@@ -137,15 +137,18 @@ def fix_filter_directive(
|
||||
if allowed_operators and filter.operator not in allowed_operators:
|
||||
return None
|
||||
args = [
|
||||
fix_filter_directive(
|
||||
arg,
|
||||
allowed_comparators=allowed_comparators,
|
||||
allowed_operators=allowed_operators,
|
||||
allowed_attributes=allowed_attributes,
|
||||
cast(
|
||||
FilterDirective,
|
||||
fix_filter_directive(
|
||||
arg,
|
||||
allowed_comparators=allowed_comparators,
|
||||
allowed_operators=allowed_operators,
|
||||
allowed_attributes=allowed_attributes,
|
||||
),
|
||||
)
|
||||
for arg in filter.arguments
|
||||
if arg is not None
|
||||
]
|
||||
args = [arg for arg in args if arg is not None]
|
||||
if not args:
|
||||
return None
|
||||
elif len(args) == 1 and filter.operator in (Operator.AND, Operator.OR):
|
||||
|
@@ -103,6 +103,13 @@ class Comparison(FilterDirective):
|
||||
attribute: str
|
||||
value: Any
|
||||
|
||||
def __init__(
|
||||
self, comparator: Comparator, attribute: str, value: Any, **kwargs: Any
|
||||
) -> None:
|
||||
super().__init__(
|
||||
comparator=comparator, attribute=attribute, value=value, **kwargs
|
||||
)
|
||||
|
||||
|
||||
class Operation(FilterDirective):
|
||||
"""A logical operation over other directives."""
|
||||
@@ -110,6 +117,11 @@ class Operation(FilterDirective):
|
||||
operator: Operator
|
||||
arguments: List[FilterDirective]
|
||||
|
||||
def __init__(
|
||||
self, operator: Operator, arguments: List[FilterDirective], **kwargs: Any
|
||||
):
|
||||
super().__init__(operator=operator, arguments=arguments, **kwargs)
|
||||
|
||||
|
||||
class StructuredQuery(Expr):
|
||||
"""A structured query."""
|
||||
@@ -120,3 +132,12 @@ class StructuredQuery(Expr):
|
||||
"""Filtering expression."""
|
||||
limit: Optional[int]
|
||||
"""Limit on the number of results."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
query: str,
|
||||
filter: Optional[FilterDirective],
|
||||
limit: Optional[int] = None,
|
||||
**kwargs: Any,
|
||||
):
|
||||
super().__init__(query=query, filter=filter, limit=limit, **kwargs)
|
||||
|
@@ -68,14 +68,14 @@ class SupabaseVectorTranslator(Visitor):
|
||||
return self.visit_operation(
|
||||
Operation(
|
||||
operator=Operator.AND,
|
||||
arguments=(
|
||||
arguments=[
|
||||
Comparison(
|
||||
comparator=comparison.comparator,
|
||||
attribute=comparison.attribute,
|
||||
value=value,
|
||||
)
|
||||
for value in comparison.value
|
||||
),
|
||||
],
|
||||
)
|
||||
)
|
||||
|
||||
|
Reference in New Issue
Block a user