-
Notifications
You must be signed in to change notification settings - Fork 6.4k
feat: extend postgres vector store with paradedb BM25 support #20024
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Restodecoca
wants to merge
4
commits into
run-llama:main
Choose a base branch
from
Restodecoca:paradedb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+7,818
−0
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
92b5072
chore: initial project setup and configuration files
Restodecoca 02bdc12
feat: add ParadeDBVectorStore implementation with BM25 and hybrid sea…
Restodecoca afc88ad
docs: add README with ParadeDB setup and usage instructions
Restodecoca 1043825
test: add initial pytest coverage for ParadeDB hybrid search
Restodecoca File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
llama-index-integrations/vector_stores/llama-index-vector-store-paradedb/.gitignore
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
llama_index/_static | ||
.DS_Store | ||
# Byte-compiled / optimized / DLL files | ||
__pycache__/ | ||
*.py[cod] | ||
*$py.class | ||
|
||
# C extensions | ||
*.so | ||
|
||
# Distribution / packaging | ||
.Python | ||
bin/ | ||
build/ | ||
develop-eggs/ | ||
dist/ | ||
downloads/ | ||
eggs/ | ||
.eggs/ | ||
etc/ | ||
include/ | ||
lib/ | ||
lib64/ | ||
parts/ | ||
sdist/ | ||
share/ | ||
var/ | ||
wheels/ | ||
pip-wheel-metadata/ | ||
share/python-wheels/ | ||
*.egg-info/ | ||
.installed.cfg | ||
*.egg | ||
MANIFEST | ||
|
||
# PyInstaller | ||
# Usually these files are written by a python script from a template | ||
# before PyInstaller builds the exe, so as to inject date/other infos into it. | ||
*.manifest | ||
*.spec | ||
|
||
# Installer logs | ||
pip-log.txt | ||
pip-delete-this-directory.txt | ||
|
||
# Unit test / coverage reports | ||
htmlcov/ | ||
.tox/ | ||
.nox/ | ||
.coverage | ||
.coverage.* | ||
.cache | ||
nosetests.xml | ||
coverage.xml | ||
*.cover | ||
*.py,cover | ||
.hypothesis/ | ||
.pytest_cache/ | ||
.ruff_cache | ||
|
||
# Translations | ||
*.mo | ||
*.pot | ||
|
||
# Django stuff: | ||
*.log | ||
local_settings.py | ||
db.sqlite3 | ||
db.sqlite3-journal | ||
|
||
# Flask stuff: | ||
instance/ | ||
.webassets-cache | ||
|
||
# Scrapy stuff: | ||
.scrapy | ||
|
||
# Sphinx documentation | ||
docs/_build/ | ||
|
||
# PyBuilder | ||
target/ | ||
|
||
# Jupyter Notebook | ||
.ipynb_checkpoints | ||
notebooks/ | ||
|
||
# IPython | ||
profile_default/ | ||
ipython_config.py | ||
|
||
# pyenv | ||
.python-version | ||
|
||
# pipenv | ||
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. | ||
# However, in case of collaboration, if having platform-specific dependencies or dependencies | ||
# having no cross-platform support, pipenv may install dependencies that don't work, or not | ||
# install all needed dependencies. | ||
#Pipfile.lock | ||
|
||
# PEP 582; used by e.g. github.com/David-OConnor/pyflow | ||
__pypackages__/ | ||
|
||
# Celery stuff | ||
celerybeat-schedule | ||
celerybeat.pid | ||
|
||
# SageMath parsed files | ||
*.sage.py | ||
|
||
# Environments | ||
.env | ||
.venv | ||
env/ | ||
venv/ | ||
ENV/ | ||
env.bak/ | ||
venv.bak/ | ||
pyvenv.cfg | ||
|
||
# Spyder project settings | ||
.spyderproject | ||
.spyproject | ||
|
||
# Rope project settings | ||
.ropeproject | ||
|
||
# mkdocs documentation | ||
/site | ||
|
||
# mypy | ||
.mypy_cache/ | ||
.dmypy.json | ||
dmypy.json | ||
|
||
# Pyre type checker | ||
.pyre/ | ||
|
||
# Jetbrains | ||
.idea | ||
modules/ | ||
*.swp | ||
|
||
# VsCode | ||
.vscode | ||
|
||
# pipenv | ||
Pipfile | ||
Pipfile.lock | ||
|
||
# pyright | ||
pyrightconfig.json |
21 changes: 21 additions & 0 deletions
21
llama-index-integrations/vector_stores/llama-index-vector-store-paradedb/LICENSE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) Jerry Liu | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. |
17 changes: 17 additions & 0 deletions
17
llama-index-integrations/vector_stores/llama-index-vector-store-paradedb/Makefile
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
GIT_ROOT ?= $(shell git rev-parse --show-toplevel) | ||
|
||
help: ## Show all Makefile targets. | ||
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[33m%-30s\033[0m %s\n", $$1, $$2}' | ||
|
||
format: ## Run code autoformatters (black). | ||
pre-commit install | ||
git ls-files | xargs pre-commit run black --files | ||
|
||
lint: ## Run linters: pre-commit (black, ruff, codespell) and mypy | ||
pre-commit install && git ls-files | xargs pre-commit run --show-diff-on-failure --files | ||
|
||
test: ## Run tests via pytest. | ||
pytest tests | ||
|
||
watch-docs: ## Build and watch documentation. | ||
sphinx-autobuild docs/ docs/_build/html --open-browser --watch $(GIT_ROOT)/llama_index/ |
90 changes: 90 additions & 0 deletions
90
llama-index-integrations/vector_stores/llama-index-vector-store-paradedb/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# LlamaIndex Vector Stores Integration: ParadeDB | ||
|
||
This module adds full ParadeDB integration enabling hybrid search with BM25 and vector similarity (HNSW) in PostgreSQL. | ||
|
||
--- | ||
|
||
## Quick Setup | ||
|
||
--- | ||
|
||
### 1. **Setup example** | ||
|
||
Run ParadeDB locally: | ||
|
||
```bash | ||
docker run --name paradedb \ | ||
-e POSTGRES_USER=postgres \ | ||
-e POSTGRES_PASSWORD=mark90 \ | ||
-e POSTGRES_DB=postgres \ | ||
-p 5432:5432 \ | ||
-d paradedb/paradedb:latest | ||
``` | ||
|
||
--- | ||
|
||
### 2. **Usage example** | ||
|
||
```python | ||
import os | ||
from dotenv import load_dotenv | ||
from sqlalchemy import make_url | ||
from llama_index.vector_stores.paradedb import ParadeDBVectorStore | ||
|
||
def get_vector_store(table_name: str = "pgvector") -> ParadeDBVectorStore: | ||
""" | ||
Creates and returns a new ParadeDBVectorStore instance using environment variables. | ||
""" | ||
load_dotenv() | ||
|
||
host = os.getenv("DB_HOST") | ||
port = os.getenv("DB_PORT") | ||
user = os.getenv("DB_USER") | ||
password = os.getenv("DB_PASSWORD") | ||
database = os.getenv("DB_DATABASE") | ||
|
||
connection_string = f"postgresql://{user}:{password}@{host}:{port}" | ||
url = make_url(connection_string) | ||
|
||
return ParadeDBVectorStore.from_params( | ||
database=database, | ||
host=url.host, | ||
password=url.password, | ||
port=url.port, | ||
user=url.username, | ||
table_name=table_name, | ||
text_search_config="english", | ||
hybrid_search=True, # needed to use bm25 | ||
use_bm25=True, | ||
embed_dim=int(os.getenv("EMBEDDING_DIM")), | ||
hnsw_kwargs={ | ||
"hnsw_m": 16, | ||
"hnsw_ef_construction": 64, | ||
"hnsw_ef_search": 40, | ||
"hnsw_dist_method": "vector_cosine_ops", | ||
}, | ||
) | ||
``` | ||
|
||
--- | ||
|
||
### Notes | ||
|
||
* Set `hybrid_search=True` and `use_bm25=True` to enable **hybrid BM25 + vector** retrieval. | ||
* You **must** use the `paradedb/paradedb:latest` image — not `pgvector/pgvector`. | ||
* The default schema name is `paradedb` to enable BM25. | ||
* Fully compatible with **llama-index-core** and other vector store interfaces. | ||
|
||
--- | ||
|
||
### Disclaimer | ||
|
||
This integration was based on the Postgres Vector Store implementation: | ||
|
||
**version = "0.5.5"** | ||
|
||
|
||
However, **`customize_query_fn`** and other Postgres-specific query customization features are **not supported** in this ParadeDB version, as the focus here is on BM25 and hybrid retrieval. | ||
|
||
Feel free to contribute and extend this module further. | ||
|
Empty file.
3 changes: 3 additions & 0 deletions
3
...r_stores/llama-index-vector-store-paradedb/llama_index/vector_stores/paradedb/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from llama_index.vector_stores.paradedb.base import ParadeDBVectorStore | ||
|
||
__all__ = ["ParadeDBVectorStore"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: should mention install command