メインコンテンツまでスキップ

__call__()

InstructorEmbeddingFunction におけるこの操作は、テキスト文字列のリストを受け取り、それらを直接ベクトル埋め込みにエンコードします。

InstructorEmbeddingFunction の __call__() メソッドは、encode_documents() および encode_queries() と同じ機能を共有します。

リクエスト構文​

python
# Instance created

ef = InstructorEmbeddingFunction()

# __call__ method will be called
ef(
texts: List[str]
) -> List[np.array]

パラメータ:

  • texts (List[str])

    文字列値のリストです。各文字列は、エンコードのために埋め込みモデルに渡されるテキストを表します。モデルは、リスト内の各文字列に対して埋め込みベクトルを生成します。

戻り値の型:

List[np.array]

戻り値:

各要素が NumPy 配列であるリストです。

例外:

なし

例​

python
from pymilvus.model.dense import InstructorEmbeddingFunction

ef = InstructorEmbeddingFunction(
model_name="hkunlp/instructor-xl", # Defaults to `hkunlp/instructor-xl`
query_instruction="Represent the question for retrieval:",
doc_instruction="Represent the document for retrieval:"
)

docs = [
"Artificial intelligence was founded as an academic discipline in 1956.",
"Alan Turing was the first person to conduct substantial research in AI.",
"Born in Maida Vale, London, Turing was raised in southern England.",
]

ef(docs)

# [array([ 1.08575663e-02, 3.87877878e-03, 3.18090729e-02, -8.12458917e-02,
# -4.68971021e-02, -5.85585833e-02, -5.95418774e-02, -8.55880603e-03,
# -5.54775111e-02, -6.08020350e-02, 1.76202394e-02, 1.06648318e-02,
# -5.89960292e-02, -7.46861771e-02, 6.60329172e-03, -4.25189249e-02,
# ...
# -1.26921125e-02, 3.01475357e-02, 8.25323071e-03, -1.88470203e-02,
# 6.04814291e-03, -2.81618331e-02, 5.91602828e-03, 7.13866428e-02],
# dtype=float32)]