fvdb FAISS 벡터 데이터베이스 주변의 간단하고 최소한의 래퍼입니다. 정규화 된 벡터가있는 L2 지수를 사용합니다.
faiss-cpu 패키지와 임베딩에 sentence-transformers 사용합니다. GPU 버전의 FAISS가 필요한 경우 (아마도 그렇지 않을 수도 있음) faiss-gpu 수동으로 설치하고 fvdb/db.hy 에서 IndexFlatL2 대신 GPUIndexFlatL2 사용할 수 있습니다. faiss-cpu 사용하는 동안에도 여전히 GPU 텍스트 임베딩 모델을 사용할 수 있습니다.
요약이 활성화 된 경우 (아래 기본값이 아닌 아래 구성 섹션 참조) 추출물 요약은 추출물과 함께 저장됩니다.
그것은 트래그와 잘 일치합니다.
일반 텍스트 (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" 먼저 sentence-transformers 사용하는 Pytorch를 설치하십시오. Pytorch의 CPU 또는 CUDA (NVIDIA GPU) 버전을 원하는지 결정해야합니다. fvdb 의 텍스트 임베드 만 있으면 기본 모델과 함께 CPU가 충분합니다.
그 다음에,
pip install fvdb그리고 그게 다야.