A generalized tool for currating and loading content into vector databases
Project description
vector-database-loader
Loading content info a vector database is relatively easy to do, especially with frameworks like LangChain. However, the process of curating the content and loading it into the database can be a bit more complex. If you are building a RAG application or similar, the quality and relevance of the content is critical. This project is meant to help with that process.
A use case for this type of project is discussed in more depth in the blog A Cost-Effective AI Chatbot Architecture with AWS Bedrock, Lambda, and Pinecone
Features
- Vector Database Support - The framework is built to support multiple vector databases but is currently implementing support for Pinecone. More vector databases will be added, but if needed you can fork the project and handle your own needs by extending the base class.
- Embedding Support - You can use any embedding provided by Langchain, which includes OpenAI, AWS Bedrock, HuggingFace, Cohere and much, much more.
- Content Curation - The framework is built configure some common content types and sources, but again is meant to be extended a needed.
- Sources include websites, local folders and google drive
- Types include PDF, Word, and Web content and google docs
- Text Splitter - This framework uses the RecursiveCharacterTextSplitter from LangChain.
This is a powerful tool that can split text into chunks of a specified size, while maintaining the context of the text. This is especially useful for long documents like web pages or PDFs.
Example
Install the package with pip:
Note: The dependencies are kind of beefy!
pip install vector-database-loader
Configuration details:
Add your Pinecone API and OpenAI keys to your .env file, see sample.env for an examples.
Code
import time
from dotenv import load_dotenv, find_dotenv
from langchain_openai import OpenAIEmbeddings
from vector_database_loader.pinecone_vector_db import PineconeVectorLoader, PineconeVectorQuery
# Define your content sources and add them to the array
web_page_content_source = {"name": "SpaceX", "type": "Website", "items": [
"https://en.wikipedia.org/wiki/SpaceX"
], "chunk_size": 512}
content_sources = [web_page_content_source]
# Load into your vector database. Be sure to add your Pinecone and OpenAI API keys to your .env file
load_dotenv(find_dotenv())
embedding_client = OpenAIEmbeddings()
index_name = "my-vectordb-index"
vector_db_loader = PineconeVectorLoader(index_name=index_name,
embedding_client=embedding_client)
vector_db_loader.load_sources(content_sources, delete_index=True)
# Query your vector database
print("Waiting 30 seconds before running the query, to make sure the data is available")
time.sleep(30) # This is needed because there is a latency in the data being available
vector_db_query = PineconeVectorQuery(index_name=index_name,
embedding_client=embedding_client)
query = "What is SpaceX's most recent rocket model being tested?"
documents = vector_db_query.query(query)
print(f"Query: {query} returned {len(documents)} results")
for doc in documents:
print(f" {doc.metadata['title']}")
print(f" {doc.page_content}")
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vector_database_loader-0.2.2.tar.gz.
File metadata
- Download URL: vector_database_loader-0.2.2.tar.gz
- Upload date:
- Size: 13.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53894ad9a79a5b58c907a660a16a8a76bb2c5faa63c96cdd0a61e9e80ab99f6c
|
|
| MD5 |
cc6704cd25fc64468d9f5482717931da
|
|
| BLAKE2b-256 |
310d4e9bc9605128265856eba996909fb92f2d0ddc3051bae866fe387cd9cac8
|
File details
Details for the file vector_database_loader-0.2.2-py3-none-any.whl.
File metadata
- Download URL: vector_database_loader-0.2.2-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.6 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
20d2f1cec7ce62508a08a52a55e23e40c6cad7836d33f568516a9a3aba1cb6c2
|
|
| MD5 |
877801ec7639672481da86311c801ebc
|
|
| BLAKE2b-256 |
745aef882c5859f9bd8efa085c334ca9d6c225427e896b9ac644a76390d02ddc
|