Vector Search with FAISS
1.0.0
该项目使用嵌入式,faiss和产品量化的嵌入式索引和产品量化实现了有效的相似性搜索系统,并使用自定义索引和Kmeans实现。它使您可以根据文本内容找到类似的讲座,从而快速检索并推荐讲座。
克隆存储库
git clone https://github.com/bariscamli/Vector-Search-with-FAISS.git
cd Vector-Search-with-FAISS创建虚拟环境(可选但建议)
python -m venv venv
source venv/bin/activate # On Windows use `venvScriptsactivate`创建虚拟环境(可选但建议)
pip install -r requirements.txt讲座数据:将您的讲座文本置于config.py中的LECTURE_FILE指定的文件中。每行应包含一个讲座。
查询数据:将查询文本放在config.py中的QUERY_FILE指定的文件中。每行应包含一个查询。讲座的示例格式.txt:
Introduction to Machine Learning
Advanced Topics in Deep Learning
Statistical Methods in Data Science
...
查询的示例格式.txt:
Basics of Neural Networks
Regression Analysis Techniques
Clustering Algorithms Overview
...
所有配置均通过config.py文件管理。关键参数包括:
File Paths
- LECTURE_FILE: Path to the lecture data file.
- QUERY_FILE: Path to the query data file.
Embedding Model
- EMBEDDING_MODEL_NAME: Name or path of the embedding model to use.
- BATCH_SIZE: Batch size for computing embeddings.
FAISS Parameters
- FAISS_EFSEARCH_VALUES: List of efSearch values for performance evaluation.
Quantization Parameters
- PQ_M: Number of sub-vector quantizers.
- PQ_NBITS: Number of bits per sub-vector.
- KMEANS_MAX_ITER: Maximum iterations for k-means during PQ training.
运行主脚本以执行完整管道:
python main.py数据加载和预处理
嵌入计算
EMBEDDING_MODEL_NAME加载嵌入模型。基线计算
FAISS索引建设和评估
efSearch值评估。性能可视化

量化
CustomIndexPQ )。示例搜索

numpymatplotlibfaiss (如果有GPU,则通过pip install faiss-cpu或faiss-gpu )loggingtransformers )