mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-20 22:03:52 +00:00
add in, nin for pinecone (#10303)
Description: Adds the in and nin comparators for pinecone seen [here](https://docs.pinecone.io/docs/metadata-filtering#metadata-query-language) --------- Co-authored-by: Bagatur <baskaryan@gmail.com>
This commit is contained in:
parent
56048b909f
commit
656d2303f7
@ -88,6 +88,8 @@ class Comparator(str, Enum):
|
|||||||
LTE = "lte"
|
LTE = "lte"
|
||||||
CONTAIN = "contain"
|
CONTAIN = "contain"
|
||||||
LIKE = "like"
|
LIKE = "like"
|
||||||
|
IN = "in"
|
||||||
|
NIN = "nin"
|
||||||
|
|
||||||
|
|
||||||
class FilterDirective(Expr, ABC):
|
class FilterDirective(Expr, ABC):
|
||||||
|
@ -20,6 +20,8 @@ class PineconeTranslator(Visitor):
|
|||||||
Comparator.LTE,
|
Comparator.LTE,
|
||||||
Comparator.GT,
|
Comparator.GT,
|
||||||
Comparator.GTE,
|
Comparator.GTE,
|
||||||
|
Comparator.IN,
|
||||||
|
Comparator.NIN,
|
||||||
)
|
)
|
||||||
"""Subset of allowed logical comparators."""
|
"""Subset of allowed logical comparators."""
|
||||||
allowed_operators = (Operator.AND, Operator.OR)
|
allowed_operators = (Operator.AND, Operator.OR)
|
||||||
@ -34,6 +36,11 @@ class PineconeTranslator(Visitor):
|
|||||||
return {self._format_func(operation.operator): args}
|
return {self._format_func(operation.operator): args}
|
||||||
|
|
||||||
def visit_comparison(self, comparison: Comparison) -> Dict:
|
def visit_comparison(self, comparison: Comparison) -> Dict:
|
||||||
|
if comparison.comparator in (Comparator.IN, Comparator.NIN) and not isinstance(
|
||||||
|
comparison.value, list
|
||||||
|
):
|
||||||
|
comparison.value = [comparison.value]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
comparison.attribute: {
|
comparison.attribute: {
|
||||||
self._format_func(comparison.comparator): comparison.value
|
self._format_func(comparison.comparator): comparison.value
|
||||||
|
@ -413,4 +413,4 @@ ignore-regex = '.*(Stati Uniti|Tense=Pres).*'
|
|||||||
# whats is a typo but used frequently in queries so kept as is
|
# whats is a typo but used frequently in queries so kept as is
|
||||||
# aapply - async apply
|
# aapply - async apply
|
||||||
# unsecure - typo but part of API, decided to not bother for now
|
# unsecure - typo but part of API, decided to not bother for now
|
||||||
ignore-words-list = 'momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure,damon,crate,aadd,symbl,precesses,accademia'
|
ignore-words-list = 'momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure,damon,crate,aadd,symbl,precesses,accademia,nin'
|
||||||
|
@ -40,4 +40,4 @@ ignore-regex = '.*(Stati Uniti|Tense=Pres).*'
|
|||||||
# whats is a typo but used frequently in queries so kept as is
|
# whats is a typo but used frequently in queries so kept as is
|
||||||
# aapply - async apply
|
# aapply - async apply
|
||||||
# unsecure - typo but part of API, decided to not bother for now
|
# unsecure - typo but part of API, decided to not bother for now
|
||||||
ignore-words-list = 'momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure,damon,crate,aadd,symbl,precesses,accademia'
|
ignore-words-list = 'momento,collison,ned,foor,reworkd,parth,whats,aapply,mysogyny,unsecure,damon,crate,aadd,symbl,precesses,accademia,nin'
|
||||||
|
Loading…
Reference in New Issue
Block a user