Context based document search
1.0.0
このプロジェクトは、ベクトルデータベースに保存されているドキュメント全体でコンテキストベースの検索を実行するためのシステムを提供します。 OpenAIの埋め込みモデルとChromaを使用すると、このツールを使用すると、テキストドキュメントのコレクションを効率的に検索し、特定のクエリに基づいて最も関連性の高い結果を取得できます。
Python 3.7以上
Openai APIキー
実行して、必要なパッケージをインストールします。
pip install -r requirements.txtgit clone https://github.com/your-username/contextual-documents-search.git cd contextual-documents-searchpython -m venv venv
source venv/bin/activate # On Windows: venvScriptsactivatepip install -r requirements.txtOPENAI_API_KEY = your_openai_api_key.txtファイルのディレクトリを検索し、 ./resumesフォルダーに配置するか、コード内の別のディレクトリを指定します。
メインスクリプトで、 VectorDBHandlerクラスをインスタンス化し、 load_or_create_db()を呼び出してベクトルストアを初期化します。
from dotenv import load_dotenv
from vector_db_handler import VectorDBHandler
# Load environment variables
load_dotenv ()
# Set up directory paths and collection name
files_directory = "./resumes"
persist_directory = "./vector_db"
collection_name = "resumes_collection"
# Initialize the vector database handler
vector_db_handler = VectorDBHandler ( files_directory , persist_directory , collection_name )
# Load or create the vector store database
vector_db_handler . load_or_create_db ()
# Define the query for the search
query = "I am looking for a software engineer with OpenAI hard skill."
docs = vector_db_handler . query_vector_store ( query )
# Output the top result
if docs :
print ( "Top matching document:" )
print ( docs [ 0 ]. page_content )
else :
print ( "No matching documents found." )