Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

community: implement _select_relevance_score_fn for tencent vectordb #28036

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions libs/community/langchain_community/vectorstores/tencentvectordb.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@
import logging
import time
from enum import Enum
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union, cast
from typing import (
Any,
Callable,
Dict,
Iterable,
List,
Optional,
Sequence,
Tuple,
Union,
cast,
)

import numpy as np
from langchain_core.documents import Document
Expand Down Expand Up @@ -168,8 +179,8 @@ def __init__(
tcvectordb = guard_import("tcvectordb")
tcollection = guard_import("tcvectordb.model.collection")
enum = guard_import("tcvectordb.model.enum")

if t_vdb_embedding:
self.embedding_model = None
if embedding is None and t_vdb_embedding:
embedding_model = [
model
for model in enum.EmbeddingModel
Expand Down Expand Up @@ -566,3 +577,17 @@ def max_marginal_relevance_search_by_vector(
)
# Reorder the values and return.
return [documents[x] for x in new_ordering if x != -1]

def _select_relevance_score_fn(self) -> Callable[[float], float]:
metric_type = self.index_params.metric_type
if metric_type == "COSINE":
return self._cosine_relevance_score_fn
elif metric_type == "L2":
return self._euclidean_relevance_score_fn
elif metric_type == "IP":
return self._max_inner_product_relevance_score_fn
else:
raise ValueError(
"No supported normalization function"
f" for distance metric of type: {metric_type}."
)
Loading