Skip to content

Commit

Permalink
vert
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 committed Dec 25, 2024
1 parent c508489 commit 4fd5bb8
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions api/core/rag/datasource/vdb/tidb_vector/tidb_vector.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,14 +203,16 @@ def search_by_vector(self, query_vector: list[float], **kwargs: Any) -> list[Doc
tidb_dist_func = "VEC_COSINE_DISTANCE"

with Session(self._engine) as session:
select_statement = sql_text(
f"""SELECT meta, text, distance FROM (
SELECT meta, text, {tidb_func}(vector, "{query_vector_str}") as distance
FROM {self._collection_name}
ORDER BY distance
LIMIT {top_k}
) t WHERE distance < {distance};"""
)
select_statement = sql_text(f"""
SELECT
meta,
text,
{tidb_dist_func}(vector, "{query_vector_str}") AS distance
FROM `{self._collection_name}`
WHERE distance <= {distance}
ORDER BY distance
LIMIT {top_k}
""")
res = session.execute(select_statement)
results = [(row[0], row[1], row[2]) for row in res]
for meta, text, distance in results:
Expand Down

0 comments on commit 4fd5bb8

Please sign in to comment.