Skip to content

Commit 6151ea7

Browse files
wlleiiwangwlleiiwangefriis
authored
community: implement _select_relevance_score_fn for tencent vectordb (langchain-ai#28036)
implement _select_relevance_score_fn for tencent vectordb fix use external embedding for tencent vectordb Co-authored-by: wlleiiwang <wlleiiwang@tencent.com> Co-authored-by: Erick Friis <erick@langchain.dev>
1 parent d34bf78 commit 6151ea7

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

libs/community/langchain_community/vectorstores/tencentvectordb.py

+28-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,18 @@
66
import logging
77
import time
88
from enum import Enum
9-
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union, cast
9+
from typing import (
10+
Any,
11+
Callable,
12+
Dict,
13+
Iterable,
14+
List,
15+
Optional,
16+
Sequence,
17+
Tuple,
18+
Union,
19+
cast,
20+
)
1021

1122
import numpy as np
1223
from langchain_core.documents import Document
@@ -168,8 +179,8 @@ def __init__(
168179
tcvectordb = guard_import("tcvectordb")
169180
tcollection = guard_import("tcvectordb.model.collection")
170181
enum = guard_import("tcvectordb.model.enum")
171-
172-
if t_vdb_embedding:
182+
self.embedding_model = None
183+
if embedding is None and t_vdb_embedding:
173184
embedding_model = [
174185
model
175186
for model in enum.EmbeddingModel
@@ -566,3 +577,17 @@ def max_marginal_relevance_search_by_vector(
566577
)
567578
# Reorder the values and return.
568579
return [documents[x] for x in new_ordering if x != -1]
580+
581+
def _select_relevance_score_fn(self) -> Callable[[float], float]:
582+
metric_type = self.index_params.metric_type
583+
if metric_type == "COSINE":
584+
return self._cosine_relevance_score_fn
585+
elif metric_type == "L2":
586+
return self._euclidean_relevance_score_fn
587+
elif metric_type == "IP":
588+
return self._max_inner_product_relevance_score_fn
589+
else:
590+
raise ValueError(
591+
"No supported normalization function"
592+
f" for distance metric of type: {metric_type}."
593+
)

0 commit comments

Comments
 (0)