Skip to content

Commit

Permalink
fix use external embedding for tencent vectordb
Browse files Browse the repository at this point in the history
  • Loading branch information
wlleiiwang committed Nov 12, 2024
1 parent 9484cc0 commit e727c87
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 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,7 @@
import logging
import time
from enum import Enum
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union, cast
from typing import Any, Dict, Iterable, List, Optional, Sequence, Tuple, Union, cast, Callable

Check failure on line 9 in libs/community/langchain_community/vectorstores/tencentvectordb.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.13

Ruff (E501)

langchain_community/vectorstores/tencentvectordb.py:9:89: E501 Line too long (94 > 88)

Check failure on line 9 in libs/community/langchain_community/vectorstores/tencentvectordb.py

View workflow job for this annotation

GitHub Actions / cd libs/community / make lint #3.9

Ruff (E501)

langchain_community/vectorstores/tencentvectordb.py:9:89: E501 Line too long (94 > 88)

import numpy as np
from langchain_core.documents import Document
Expand Down Expand Up @@ -168,8 +168,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 +566,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}."
)

0 comments on commit e727c87

Please sign in to comment.