@@ -821,6 +821,131 @@ describe("PGVectorStore with schema", () => {
821
821
} ) ;
822
822
} ) ;
823
823
824
+ describe ( "PGVectorStore with skipInitializationCheck" , ( ) => {
825
+ let pgvectorVectorStore : PGVectorStore ;
826
+ const tableName = "testlangchain_skip_init" ;
827
+
828
+ afterEach ( async ( ) => {
829
+ const pool = new pg . Pool ( postgresConnectionOptions ) ;
830
+ await pool . query ( `DROP TABLE IF EXISTS "${ tableName } "` ) ;
831
+ await pool . end ( ) ;
832
+ } ) ;
833
+
834
+ test ( "skipInitializationCheck=false (default) should initialize tables" , async ( ) => {
835
+ const config : PGVectorStoreArgs = {
836
+ postgresConnectionOptions,
837
+ tableName,
838
+ columns : {
839
+ idColumnName : "id" ,
840
+ vectorColumnName : "vector" ,
841
+ contentColumnName : "content" ,
842
+ metadataColumnName : "metadata" ,
843
+ } ,
844
+ } ;
845
+
846
+ pgvectorVectorStore = await PGVectorStore . initialize (
847
+ embeddingsEngine ,
848
+ config
849
+ ) ;
850
+
851
+ const result = await pgvectorVectorStore . pool . query (
852
+ `SELECT EXISTS (
853
+ SELECT FROM information_schema.tables
854
+ WHERE table_schema = 'public'
855
+ AND table_name = '${ tableName } '
856
+ )`
857
+ ) ;
858
+
859
+ expect ( result . rows [ 0 ] . exists ) . toBe ( true ) ;
860
+ await pgvectorVectorStore . end ( ) ;
861
+ } ) ;
862
+
863
+ test ( "skipInitializationCheck=true should skip table initialization" , async ( ) => {
864
+ const config : PGVectorStoreArgs = {
865
+ postgresConnectionOptions,
866
+ tableName,
867
+ skipInitializationCheck : true ,
868
+ columns : {
869
+ idColumnName : "id" ,
870
+ vectorColumnName : "vector" ,
871
+ contentColumnName : "content" ,
872
+ metadataColumnName : "metadata" ,
873
+ } ,
874
+ } ;
875
+
876
+ pgvectorVectorStore = await PGVectorStore . initialize (
877
+ embeddingsEngine ,
878
+ config
879
+ ) ;
880
+
881
+ const tableExists = await pgvectorVectorStore . pool . query (
882
+ `SELECT EXISTS (
883
+ SELECT FROM information_schema.tables
884
+ WHERE table_schema = 'public'
885
+ AND table_name = '${ tableName } '
886
+ )`
887
+ ) ;
888
+
889
+ expect ( tableExists . rows [ 0 ] . exists ) . toBe ( false ) ;
890
+
891
+ await pgvectorVectorStore . end ( ) ;
892
+ } ) ;
893
+
894
+ test ( "skipInitializationCheck=true should work with addDocuments" , async ( ) => {
895
+ const setupPool = new pg . Pool ( postgresConnectionOptions ) ;
896
+
897
+ await setupPool . query ( `CREATE EXTENSION IF NOT EXISTS vector` ) ;
898
+ await setupPool . query ( `
899
+ CREATE TABLE "${ tableName } " (
900
+ "id" uuid NOT NULL DEFAULT gen_random_uuid() PRIMARY KEY,
901
+ "content" text,
902
+ "metadata" jsonb,
903
+ "vector" vector(1536)
904
+ );
905
+ ` ) ;
906
+
907
+ await setupPool . end ( ) ;
908
+
909
+ const config : PGVectorStoreArgs = {
910
+ postgresConnectionOptions,
911
+ tableName,
912
+ skipInitializationCheck : true ,
913
+ columns : {
914
+ idColumnName : "id" ,
915
+ vectorColumnName : "vector" ,
916
+ contentColumnName : "content" ,
917
+ metadataColumnName : "metadata" ,
918
+ } ,
919
+ } ;
920
+
921
+ pgvectorVectorStore = await PGVectorStore . initialize (
922
+ embeddingsEngine ,
923
+ config
924
+ ) ;
925
+
926
+ const documents = [
927
+ { pageContent : "Hello world" , metadata : { source : "test" } } ,
928
+ {
929
+ pageContent : "Testing skipInitializationCheck" ,
930
+ metadata : { source : "test" } ,
931
+ } ,
932
+ ] ;
933
+
934
+ await pgvectorVectorStore . addDocuments ( documents ) ;
935
+
936
+ const query = await embeddingsEngine . embedQuery ( "Hello" ) ;
937
+ const results = await pgvectorVectorStore . similaritySearchVectorWithScore (
938
+ query ,
939
+ 1
940
+ ) ;
941
+
942
+ expect ( results ) . toHaveLength ( 1 ) ;
943
+ expect ( results [ 0 ] [ 0 ] . pageContent ) . toBe ( "Hello world" ) ;
944
+
945
+ await pgvectorVectorStore . end ( ) ;
946
+ } ) ;
947
+ } ) ;
948
+
824
949
describe ( "PGVectorStore with HNSW index" , ( ) => {
825
950
let pgvectorVectorStore : PGVectorStore ;
826
951
const tableName = "testlangchain" ;
0 commit comments