@@ -843,16 +843,19 @@ describe("PGVectorStore with skipInitializationCheck", () => {
843
843
} ,
844
844
} ;
845
845
846
- pgvectorVectorStore = await PGVectorStore . initialize ( embeddingsEngine , config ) ;
847
-
846
+ pgvectorVectorStore = await PGVectorStore . initialize (
847
+ embeddingsEngine ,
848
+ config
849
+ ) ;
850
+
848
851
const result = await pgvectorVectorStore . pool . query (
849
852
`SELECT EXISTS (
850
853
SELECT FROM information_schema.tables
851
854
WHERE table_schema = 'public'
852
855
AND table_name = '${ tableName } '
853
856
)`
854
857
) ;
855
-
858
+
856
859
expect ( result . rows [ 0 ] . exists ) . toBe ( true ) ;
857
860
await pgvectorVectorStore . end ( ) ;
858
861
} ) ;
@@ -869,25 +872,28 @@ describe("PGVectorStore with skipInitializationCheck", () => {
869
872
metadataColumnName : "metadata" ,
870
873
} ,
871
874
} ;
872
-
873
- pgvectorVectorStore = await PGVectorStore . initialize ( embeddingsEngine , config ) ;
874
-
875
+
876
+ pgvectorVectorStore = await PGVectorStore . initialize (
877
+ embeddingsEngine ,
878
+ config
879
+ ) ;
880
+
875
881
const tableExists = await pgvectorVectorStore . pool . query (
876
882
`SELECT EXISTS (
877
883
SELECT FROM information_schema.tables
878
884
WHERE table_schema = 'public'
879
885
AND table_name = '${ tableName } '
880
886
)`
881
887
) ;
882
-
888
+
883
889
expect ( tableExists . rows [ 0 ] . exists ) . toBe ( false ) ;
884
-
890
+
885
891
await pgvectorVectorStore . end ( ) ;
886
892
} ) ;
887
893
888
894
test ( "skipInitializationCheck=true should work with addDocuments" , async ( ) => {
889
895
const setupPool = new pg . Pool ( postgresConnectionOptions ) ;
890
-
896
+
891
897
await setupPool . query ( `CREATE EXTENSION IF NOT EXISTS vector` ) ;
892
898
await setupPool . query ( `
893
899
CREATE TABLE "${ tableName } " (
@@ -897,9 +903,9 @@ describe("PGVectorStore with skipInitializationCheck", () => {
897
903
"vector" vector(1536)
898
904
);
899
905
` ) ;
900
-
906
+
901
907
await setupPool . end ( ) ;
902
-
908
+
903
909
const config : PGVectorStoreArgs = {
904
910
postgresConnectionOptions,
905
911
tableName,
@@ -911,22 +917,31 @@ describe("PGVectorStore with skipInitializationCheck", () => {
911
917
metadataColumnName : "metadata" ,
912
918
} ,
913
919
} ;
914
-
915
- pgvectorVectorStore = await PGVectorStore . initialize ( embeddingsEngine , config ) ;
916
-
920
+
921
+ pgvectorVectorStore = await PGVectorStore . initialize (
922
+ embeddingsEngine ,
923
+ config
924
+ ) ;
925
+
917
926
const documents = [
918
927
{ pageContent : "Hello world" , metadata : { source : "test" } } ,
919
- { pageContent : "Testing skipInitializationCheck" , metadata : { source : "test" } } ,
928
+ {
929
+ pageContent : "Testing skipInitializationCheck" ,
930
+ metadata : { source : "test" } ,
931
+ } ,
920
932
] ;
921
-
933
+
922
934
await pgvectorVectorStore . addDocuments ( documents ) ;
923
-
935
+
924
936
const query = await embeddingsEngine . embedQuery ( "Hello" ) ;
925
- const results = await pgvectorVectorStore . similaritySearchVectorWithScore ( query , 1 ) ;
926
-
937
+ const results = await pgvectorVectorStore . similaritySearchVectorWithScore (
938
+ query ,
939
+ 1
940
+ ) ;
941
+
927
942
expect ( results ) . toHaveLength ( 1 ) ;
928
943
expect ( results [ 0 ] [ 0 ] . pageContent ) . toBe ( "Hello world" ) ;
929
-
944
+
930
945
await pgvectorVectorStore . end ( ) ;
931
946
} ) ;
932
947
} ) ;
0 commit comments