fvdb
1.0.0
fvdb是FAISS矢量数据库周围的简单,最小的包装器。它使用具有归一化向量的L2索引。
它使用faiss-cpu软件包和sentence-transformers进行嵌入。如果您需要GPU版本的faiss(可能不是),则可以手动安装faiss-gpu并在fvdb/db.hy中使用GPUIndexFlatL2而不是IndexFlatL2 。即使使用faiss-cpu您仍然可以使用GPU文本嵌入模型。
如果启用了摘要(不是默认值,请参见下面的配置部分),则将与提取物一起存储提取物的摘要。
它与trag息息。
除纯文本以外的任何输入(Markdown,Asciidoc,RST,源代码等)都超出了范围。您应该在单独的步骤中转换为纯文本中的许多可用软件包(非结构化,trafiltura,docling等)之一。
import hy # fvdb is written in Hy, but you can use it from python too
from fvdb import faiss , ingest , similar , sources , write
# data ingestion
v = faiss ()
ingest ( v , "doc.md" )
ingest ( v , "docs-dir" )
write ( v , "/tmp/test.fvdb" ) # defaults to $XDG_DATA_HOME/fvdb (~/.local/share/fvdb/ on Linux)
# search
results = similar ( v , "some query text" )
results = marginal ( v , "some query text" ) # not yet implemented
# information, management
sources ( v )
{ ...
'docs-dir/Once More to the Lake.txt' ,
'docs-dir/Politics and the English Language.txt' ,
'docs-dir/Reflections on Gandhi.txt' ,
'docs-dir/Shooting an elephant.txt' ,
'docs-dir/The death of the moth.txt' ,
... }
info ( v )
{ 'records' : 42 ,
'embeddings' : 42 ,
'embedding_dimension' : 1024 ,
'is_trained' : True ,
'path' : '/tmp/test-vdb' ,
'sources' : 24 ,
'embedding_model' : 'Alibaba-NLP/gte-large-en-v1.5' }
nuke ( v )这些也可以从命令行获得。
$ # defaults to $XDG_DATA_HOME/fvdb (~/.local/share/fvdb/ on Linux)
# data ingestion (saves on exit)
$ fvdb ingest doc.md
Adding 2 records
$ fvdb ingest docs-dir
Adding 42 records
$ # search
$ fvdb similar -j " some query text " > results.json # --json / -j gives json output
$ fvdb similar -r 2 " George Orwell's formative experience as a policeman in colonial Burma "
# defaults to tabulated output (not all fields will be shown)
score source added page length
-------- ---------------------------------- -------------------------------- ------ --------
0.579925 docs-dir/A hanging.txt 2024-11-05T11:37:26.232773+00:00 0 2582
0.526988 docs-dir/Shooting an elephant.txt 2024-11-05T11:37:43.891659+00:00 0 3889
$ fvdb marginal " some query text " # not yet implemented
$ # information, management
$ fvdb sources
...
docs-dir/Once More to the Lake.txt
docs-dir/Politics and the English Language.txt
docs-dir/Reflections on Gandhi.txt
docs-dir/Shooting an elephant.txt
docs-dir/The death of the moth.txt
...
$ fvdb info
------------------- -----------------------------
records 44
embeddings 44
embedding_dimension 1024
is_trained True
path /tmp/test
sources 24
embedding_model Alibaba-NLP/gte-large-en-v1.5
------------------- -----------------------------
$ fvdb nuke寻找$XDG_CONFIG_HOME/fvdb/conf.toml ,否则使用默认值。
您不能在单个FVDB中混合嵌入式型号。
这是一个例子。
# Sets the default path to something other than $XDG_CONFIG_HOME/fvdb/conf.toml
path = " /tmp/test.fvdb "
# Summaries are useful if you use an embedding model with large maximum sequence length,
# for example, gte-large-en-v1.5 has maximum sequence length of 8192.
summary = true
# A conservative default model, maximum sequence length of 512,
# so no point using summaries.
embeddings.model = " all-mpnet-base-v2 "
# # Some models need extra options
# embeddings.model = "Alibaba-NLP/gte-large-en-v1.5"
# embeddings.trust_remote_code = true
# # You can put some smaller models on a cpu, but larger models will be slow
# embeddings.device = "cpu" 首先安装pytorch,该pytorch由sentence-transformers使用。您必须决定是否想要Pytorch的CPU或CUDA(NVIDIA GPU)版本。对于fvdb的文本嵌入,使用默认模型,CPU就足够了。
然后,
pip install fvdb就是这样。