• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

georgia-tech-db / eva / #758

04 Sep 2023 08:37PM UTC coverage: 0.0% (-78.3%) from 78.333%
#758

push

circle-ci

hershd23
Increased underline length in at line 75 in text_summarization.rst
	modified:   docs/source/benchmarks/text_summarization.rst

0 of 11303 relevant lines covered (0.0%)

0.0 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/evadb/udfs/ndarray/similarity.py
1
# coding=utf-8
2
# Copyright 2018-2023 EvaDB
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
import pandas as pd
×
16

17
from evadb.udfs.abstract.abstract_udf import AbstractUDF
×
18
from evadb.utils.generic_utils import try_to_import_faiss
×
19

20

21
class Similarity(AbstractUDF):
×
22
    def _get_distance(self, numpy_distance):
×
23
        return numpy_distance[0][0]
×
24

25
    def setup(self):
×
26
        try_to_import_faiss()
×
27
        pass
×
28

29
    @property
×
30
    def name(self):
×
31
        return "Similarity"
×
32

33
    def forward(self, df: pd.DataFrame) -> pd.DataFrame:
×
34
        """
35
        Get similarity score between two feature vectors: 1. feature vector of an opened image;
36
        and 2. feature vector from base table.
37
        """
38

39
        def _similarity(row: pd.Series) -> float:
×
40
            open_feat_np, base_feat_np = (
×
41
                row.iloc[0],
42
                row.iloc[1],
43
            )
44

45
            # TODO: currently system takes care of feature vector shape
46
            # transformation. Improve this later on.
47
            # Transform to 2D.
48
            open_feat_np = open_feat_np.reshape(1, -1)
×
49
            base_feat_np = base_feat_np.reshape(1, -1)
×
50
            import faiss
×
51

52
            distance_np = faiss.pairwise_distances(open_feat_np, base_feat_np)
×
53

54
            return self._get_distance(distance_np)
×
55

56
        ret = pd.DataFrame()
×
57
        ret["distance"] = df.apply(_similarity, axis=1)
×
58
        return ret
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc