feat(rag): add pgvector vector store backend#1285
Open
Avi-47 wants to merge 1 commit intomofa-org:mainfrom
Open
feat(rag): add pgvector vector store backend#1285Avi-47 wants to merge 1 commit intomofa-org:mainfrom
Avi-47 wants to merge 1 commit intomofa-org:mainfrom
Conversation
0aa9d4f to
215cbc0
Compare
215cbc0 to
9c02962
Compare
Contributor
Author
|
Hi @lijingrs @yangrudan, |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
This PR adds a new pgvector-backed VectorStore implementation for the MoFA RAG pipeline. The implementation uses PostgreSQL with the pgvector extension to provide persistent vector storage with similarity search capabilities.
Related Work
This PR is part of a series of improvements to MoFA's RAG pipeline.
Related issue:
Related PRs:
Together these changes extend MoFA's RAG system with:
Motivation
The MoFA framework currently supports Qdrant as a vector store backend. Adding pgvector support provides users with more flexibility to use PostgreSQL - a widely-adopted database that many organizations already have in their infrastructure. This enables:
Architecture
The implementation follows the same design pattern as the existing QdrantVectorStore:
Key Components
Implementation Details
ON CONFLICTfor upsert semantics<->operatorUsage
Enable the feature in Cargo.toml:
Example usage:
Testing Instructions
1. Start PostgreSQL with pgvector
Using Docker:
Or using Docker Compose:
2. Run integration tests (requires database)
Test Results
All pgvector tests passed locally.
Output:
3. Run a simple similarity query test
Create a test script:
Dependencies Added
tokio-postgres = "0.7"- Async PostgreSQL clientpgvector = "0.2"- Rust types for pgvectorFiles Changed
crates/mofa-foundation/Cargo.toml- Added pgvector feature and dependenciescrates/mofa-foundation/src/rag/mod.rs- Added storage module exportcrates/mofa-foundation/src/rag/storage/pgvector.rs- New implementationcrates/mofa-foundation/tests/pgvector_store_test.rs- New test fileBackward Compatibility
This change is fully backward compatible. The pgvector feature is optional and disabled by default. Existing code using other vector stores (Qdrant, InMemory) is unaffected.
Related Work
Part of Task #27 – RAG Pipeline improvements.
Future work may include: