Skip to content

Bug: Encountering bug when i excute vector search. #189

@Ol1ver0413

Description

@Ol1ver0413

Describe the bug

I encounter a fail message report when executing vector search operation. Like below:

My action:
metric = {
VectorDistance.COSINE: "cosine",
VectorDistance.EUCLIDEAN: "euclidean",
VectorDistance.DOT: "dot",
}.get(self.distance)

    if not metric:
        raise ValueError(f"Unsupported distance metric: {self.distance}")

    with Surreal(self.url) as db:
        db.signin({"username": self.user, "password": self.password})
        db.use(self.ns, self.db)
        print(q.query_vector)
        query = f"""
            SELECT payload,
                   vector::distance::{metric}(embedding, {q.query_vector}) AS score
            FROM {self.table}
            WHERE embedding <|{q.top_k},{metric}|> {q.query_vector}
            ORDER BY score;
        """

        results = db.query_raw(query)
        return results

failed message output:
{'error': {'code': -32000, 'message': 'There was a problem with the database: Parse error: Invalid function/constant path\n --> [1:8]\n |\n1 | SELECT distance(embedding, [1.1, 2.1, 3.1, 4.1]) AS score FROM lyz_tb;\n | ^^^^^^^^ \n'}, 'id': '0a93d77c-206e-49c5-82e5-7a4c012e53ea'}

Steps to reproduce

I want to merge surrealdb into Camel.
def query(self, q: VectorDBQuery) -> List[VectorDBQueryResult]:
r"""
Perform a top-k similarity search using the configured distance metric.

    Args:
        q (VectorDBQuery): Query containing the query vector and top_k value.

    Returns:
        List[VectorDBQueryResult]: Ranked list of matching records with similarity scores.
    """
    metric = {
        VectorDistance.COSINE: "cosine",
        VectorDistance.EUCLIDEAN: "euclidean",
        VectorDistance.DOT: "dot",
    }.get(self.distance)

    if not metric:
        raise ValueError(f"Unsupported distance metric: {self.distance}")

    with Surreal(self.url) as db:
        db.signin({"username": self.user, "password": self.password})
        db.use(self.ns, self.db)
        print(q.query_vector)
        query = f"""
            SELECT payload,
                   vector::distance::{metric}(embedding, {q.query_vector}) AS score
            FROM {self.table}
            WHERE embedding <|{q.top_k},{metric}|> {q.query_vector}
            ORDER BY score;
        """

        results = db.query_raw(query)
        return results

Expected behaviour

How to fix this problem.

SurrealDB version

SurrealDB command-line interface and server 2.3.6 for linux on x86_64

surrealdb.py version

SurrealDB command-line interface and server 2.3.6 for linux on x86_64

Contact Details

[email protected]

Is there an existing issue for this?

  • I have searched the existing issues

Code of Conduct for repository surrealdb/surrealdb.py

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions