Use args option in jaguar so it takes more options in similarity search (#15080)

- **Description:** replace score_threshold with args
  - **Issue:** needs a way to pass more options to similarity search
  - **Dependencies:** None
  - **Twitter handle:** @workbot

---------

Co-authored-by: JY <jyjy@jaguardb>
This commit is contained in:
JaguarDB 2024-01-02 15:53:06 -08:00 committed by GitHub
parent 37ad6ec248
commit 02f59c2035
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -176,7 +176,8 @@ class Jaguar(VectorStore):
podstore = self._pod + "." + self._store podstore = self._pod + "." + self._store
q = "insert into " + podstore + " (" q = "insert into " + podstore + " ("
q += vcol + "," + textcol + ") values ('" + values_comma q += vcol + "," + textcol + ") values ('" + values_comma
q += "','" + texts[i] + "')" txt = texts[i].replace("'", "\\'")
q += "','" + txt + "')"
js = self.run(q, False) js = self.run(q, False)
ids.append(js["zid"]) ids.append(js["zid"])
i += 1 i += 1
@ -199,7 +200,8 @@ class Jaguar(VectorStore):
podstore = self._pod + "." + self._store podstore = self._pod + "." + self._store
q = "insert into " + podstore + " (" q = "insert into " + podstore + " ("
q += names_comma + "," + textcol + ") values (" + values_comma q += names_comma + "," + textcol + ") values (" + values_comma
q += ",'" + texts[i] + "')" txt = texts[i].replace("'", "\\'")
q += ",'" + txt + "')"
if filecol != "": if filecol != "":
js = self.run(q, True) js = self.run(q, True)
else: else:
@ -215,7 +217,7 @@ class Jaguar(VectorStore):
k: int = 3, k: int = 3,
fetch_k: int = -1, fetch_k: int = -1,
where: Optional[str] = None, where: Optional[str] = None,
score_threshold: Optional[float] = -1.0, args: Optional[str] = None,
metadatas: Optional[List[str]] = None, metadatas: Optional[List[str]] = None,
**kwargs: Any, **kwargs: Any,
) -> List[Tuple[Document, float]]: ) -> List[Tuple[Document, float]]:
@ -227,9 +229,7 @@ class Jaguar(VectorStore):
lambda_val: lexical match parameter for hybrid search. lambda_val: lexical match parameter for hybrid search.
where: the where clause in select similarity. For example a where: the where clause in select similarity. For example a
where can be "rating > 3.0 and (state = 'NV' or state = 'CA')" where can be "rating > 3.0 and (state = 'NV' or state = 'CA')"
score_threshold: minimal score threshold for the result. args: extra options passed to select similarity
If defined, results with score less than this value will be
filtered out.
kwargs: vector_index=vcol, vector_type=cosine_fraction_float kwargs: vector_index=vcol, vector_type=cosine_fraction_float
Returns: Returns:
List of Documents most similar to the query and score for each. List of Documents most similar to the query and score for each.
@ -254,7 +254,9 @@ class Jaguar(VectorStore):
+ ",type=" + ",type="
+ vtype + vtype
) )
q += ",with_score=yes,with_text=yes,score_threshold=" + str(score_threshold) q += ",with_score=yes,with_text=yes"
if args is not None:
q += "," + args
if metadatas is not None: if metadatas is not None:
meta = "&".join(metadatas) meta = "&".join(metadatas)