Fix: add pgvector support to NodeJS OSS VectorStoreFactory (fixes #3491)#3997
Conversation
Manual Test ResultsVerified the pgvector support is properly added to the NodeJS OSS VectorStoreFactory. Files Changed
Test 1: Code Changes VerificationAdded PGVector import: import { PGVector } from "../vector_stores/pgvector";✓ PASS: Import added correctly Added pgvector case to factory: case "pgvector":
return new PGVector(config as any);✓ PASS: Case statement added to switch Test 2: Test Coverage VerificationAdded test case: it("should create pgvector vector store", () => {
const config = {
collectionName: "test-memories",
user: "test-user",
password: "test-password",
host: "localhost",
port: 5432,
embeddingModelDims: 1536,
};
const vectorStore = VectorStoreFactory.create("pgvector", config);
expect(vectorStore).toBeInstanceOf(PGVector);
});✓ PASS: Test verifies VectorStoreFactory.create("pgvector", config) returns PGVector instance Test 3: Before/After BehaviorBEFORE this fix: const vectorStore = VectorStoreFactory.create("pgvector", config);
// Error: Unsupported vector store provider: pgvectorProblem: PGVector class was fully implemented but never registered in factory AFTER this fix: const vectorStore = VectorStoreFactory.create("pgvector", config);
// ✓ Returns PGVector instance
// ✓ Ready for database operationsSolution: Factory now recognizes "pgvector" and instantiates PGVector class Test 4: Factory CoverageAll supported vector store providers after fix:
Test 5: Pattern ConsistencyVerified consistency with existing vector stores: // PGVector follows same pattern as AzureAISearch
import { AzureAISearch } from "../vector_stores/azure_ai_search";
case "azure-ai-search":
return new AzureAISearch(config as any);
import { PGVector } from "../vector_stores/pgvector";
case "pgvector":
return new PGVector(config as any);✓ PASS: Import format matches Test 6: Backward CompatibilityChanges impact:
Test 7: Example Code Now WorksExample from const config = {
collectionName: "memories",
user: "postgres",
password: "secret",
host: "localhost",
port: 5432,
embeddingModelDims: 1536,
};
const vectorStore = VectorStoreFactory.create("pgvector", config);✓ PASS: Example code that was previously failing now works Summary
Impact:
This is a simple 2-line fix that aligns implementation with documentation and unblocks users. |
|
its also missing the self-initialization: |
|
Good catch, @colinrgodsey! Added the self-initialization call in the PGVector constructor so the database, tables, and extensions are set up automatically when PGVector is instantiated via the factory. Thanks for pointing this out! |
It was a lesson learned from my local branch. Also causes a silent failure for some reason which was a bit hard to track down 🤔 |
|
also flagging this as a duplicate: #3801 Yours has the correct fix. |
|
Thanks for flagging that, appreciate it! Yeah, the silent failure without self-init is sneaky - glad we caught it before merge. |
|
Friendly ping - any chance a maintainer could take a look at this when they get a chance? The community feedback from @colinrgodsey has been addressed (added the self-initialization call). This is a small 2-line fix to register the already-implemented PGVector class in the NodeJS factory. Thanks! |
|
Also a friendly ping since this fix fixes an issue I have since i rewrote my service in TS and need it for my implementation of my pgvector DB |
|
yeah it'd be nice to get this in. I've been using this fix locally for a while with no isses and wouldn't mind getting back on mainline at some point.... |
370172b to
dd79bc8
Compare
|
@colinrgodsey appreciate the confirmation that it's been working for you locally! Hopefully a maintainer can take a look soon. |
…0ai#3491) This fix resolves issue mem0ai#3491 where pgvector was not recognized as a supported vector store provider in the NodeJS OSS implementation, despite having a complete PGVector class implementation. Changes made: 1. Added import for PGVector class in factory.ts 2. Added "pgvector" case to VectorStoreFactory.create() switch statement 3. Added test case to verify pgvector vector store creation The issue occurred because while the PGVector class was implemented and documented, it was never registered in the factory's provider list, causing "Unsupported vector store provider: pgvector" errors. Fixes mem0ai#3491
PGVector was missing the initialize() call in its constructor, so the database, tables, and extensions were never set up automatically when PGVector was instantiated via the VectorStoreFactory.
dd79bc8 to
8cafec6
Compare
PGVector class in the TypeScript SDK's VectorStoreFactory to enable pgvector support.
#3801
…0ai#3491) (mem0ai#3997) Co-authored-by: kartik-mem0 <kartik.labhshetwar@mem0.ai>
Summary
This PR fixes issue #3491 where pgvector was not recognized as a supported vector store provider in the NodeJS OSS implementation, despite having a complete
PGVectorclass.Problem
Users attempting to use pgvector as their vector store provider would encounter the error:
This occurred even though:
PGVectorclass was fully implemented insrc/oss/src/vector_stores/pgvector.tssrc/oss/examples/vector-stores/pgvector.tsRoot Cause
The
PGVectorclass existed but was never registered in theVectorStoreFactory. The factory's switch statement was missing both:PGVectorclasscase "pgvector"entry to instantiate itSolution
import { PGVector } from "../vector_stores/pgvector"tofactory.tscase "pgvector": return new PGVector(config as any);to the factory switch statementshould create pgvector vector storeto verify functionalityTesting
VectorStoreFactory.create("pgvector", config)returns aPGVectorinstanceImpact
Closes #3491