跳到主要内容

默认嵌入式函数

嵌入函数将文本文档转换为向量嵌入,以进行相似性搜索。pyseekdb 支持内置和自定义嵌入函数。

如果没有指定,DefaultEmbeddingFunction 则是默认的嵌入函数。该函数已在 seekdb 内存在,无需再创建。

示例如下:

from pyseekdb import DefaultEmbeddingFunction

# Use default model (all-MiniLM-L6-v2, 384 dimensions)
ef = DefaultEmbeddingFunction()

# Use custom model
ef = DefaultEmbeddingFunction()

# Get embedding dimension
print(f"Dimension: {ef.dimension}") # 384

# Generate embeddings
embeddings = ef(["Hello world", "How are you?"])
print(f"Generated {len(embeddings)} embeddings, each with {len(embeddings[0])} dimensions")

相关操作

如果您需要使用自定义函数,可以参考以下文档创建和使用自定义函数: