@@ -31,31 +31,42 @@ public sealed class GraphRagApplicationFixture : IAsyncLifetime
3131
3232 public async Task InitializeAsync ( )
3333 {
34- _neo4jContainer = new Neo4jBuilder ( )
35- . WithImage ( "neo4j:5.23.0-community" )
36- . WithEnvironment ( "NEO4J_ACCEPT_LICENSE_AGREEMENT" , "yes" )
37- . WithEnvironment ( "NEO4J_PLUGINS" , "[\" apoc\" ]" )
38- . WithEnvironment ( "NEO4J_dbms_default__listen__address" , "0.0.0.0" )
39- . WithEnvironment ( "NEO4J_dbms_default__advertised__address" , "localhost" )
40- . WithEnvironment ( "NEO4J_AUTH" , $ "neo4j/{ Neo4jPassword } ")
41- . WithWaitStrategy ( Wait . ForUnixContainer ( ) . UntilInternalTcpPortIsAvailable ( 7687 ) )
42- . Build ( ) ;
43-
44- _postgresContainer = new PostgreSqlBuilder ( )
45- . WithImage ( "apache/age:latest" )
46- . WithDatabase ( PostgresDatabase )
47- . WithUsername ( "postgres" )
48- . WithPassword ( PostgresPassword )
49- . WithCleanUp ( true )
50- . WithWaitStrategy ( Wait . ForUnixContainer ( ) . UntilInternalTcpPortIsAvailable ( 5432 ) )
51- . Build ( ) ;
52-
53- await Task . WhenAll ( _neo4jContainer . StartAsync ( ) , _postgresContainer . StartAsync ( ) ) . ConfigureAwait ( false ) ;
54-
55- await EnsurePostgresDatabaseAsync ( ) . ConfigureAwait ( false ) ;
56-
57- var boltEndpoint = new Uri ( _neo4jContainer . GetConnectionString ( ) , UriKind . Absolute ) ;
58- var postgresConnection = _postgresContainer . GetConnectionString ( ) ;
34+ var skipContainers = string . Equals (
35+ Environment . GetEnvironmentVariable ( "GRAPHRAG_SKIP_TESTCONTAINERS" ) ,
36+ "1" ,
37+ StringComparison . OrdinalIgnoreCase ) ;
38+
39+ Uri ? boltEndpoint = null ;
40+ string ? postgresConnection = null ;
41+
42+ if ( ! skipContainers )
43+ {
44+ _neo4jContainer = new Neo4jBuilder ( )
45+ . WithImage ( "neo4j:5.23.0-community" )
46+ . WithEnvironment ( "NEO4J_ACCEPT_LICENSE_AGREEMENT" , "yes" )
47+ . WithEnvironment ( "NEO4J_PLUGINS" , "[\" apoc\" ]" )
48+ . WithEnvironment ( "NEO4J_dbms_default__listen__address" , "0.0.0.0" )
49+ . WithEnvironment ( "NEO4J_dbms_default__advertised__address" , "localhost" )
50+ . WithEnvironment ( "NEO4J_AUTH" , $ "neo4j/{ Neo4jPassword } ")
51+ . WithWaitStrategy ( Wait . ForUnixContainer ( ) . UntilInternalTcpPortIsAvailable ( 7687 ) )
52+ . Build ( ) ;
53+
54+ _postgresContainer = new PostgreSqlBuilder ( )
55+ . WithImage ( "apache/age:latest" )
56+ . WithDatabase ( PostgresDatabase )
57+ . WithUsername ( "postgres" )
58+ . WithPassword ( PostgresPassword )
59+ . WithCleanUp ( true )
60+ . WithWaitStrategy ( Wait . ForUnixContainer ( ) . UntilInternalTcpPortIsAvailable ( 5432 ) )
61+ . Build ( ) ;
62+
63+ await Task . WhenAll ( _neo4jContainer . StartAsync ( ) , _postgresContainer . StartAsync ( ) ) . ConfigureAwait ( false ) ;
64+ await EnsurePostgresDatabaseAsync ( ) . ConfigureAwait ( false ) ;
65+
66+ boltEndpoint = new Uri ( _neo4jContainer . GetConnectionString ( ) , UriKind . Absolute ) ;
67+ postgresConnection = _postgresContainer . GetConnectionString ( ) ;
68+ }
69+
5970 var cosmosConnectionString = Environment . GetEnvironmentVariable ( "COSMOS_EMULATOR_CONNECTION_STRING" ) ;
6071 var includeCosmos = ! string . IsNullOrWhiteSpace ( cosmosConnectionString ) ;
6172
@@ -69,39 +80,55 @@ public async Task InitializeAsync()
6980
7081 services . AddGraphRag ( ) ;
7182
72- services . AddKeyedSingleton < WorkflowDelegate > ( "neo4j-seed" , static ( _ , _ ) => async ( config , context , token ) =>
83+ if ( ! skipContainers && boltEndpoint is not null && postgresConnection is not null )
7384 {
74- var graph = context . Services . GetRequiredKeyedService < IGraphStore > ( "neo4j" ) ;
75- await graph . InitializeAsync ( token ) . ConfigureAwait ( false ) ;
76- await graph . UpsertNodeAsync ( "alice" , "Person" , new Dictionary < string , object ? > { [ "name" ] = "Alice" } , token ) . ConfigureAwait ( false ) ;
77- await graph . UpsertNodeAsync ( "bob" , "Person" , new Dictionary < string , object ? > { [ "name" ] = "Bob" } , token ) . ConfigureAwait ( false ) ;
78- await graph . UpsertRelationshipAsync ( "alice" , "bob" , "KNOWS" , new Dictionary < string , object ? > { [ "since" ] = 2024 } , token ) . ConfigureAwait ( false ) ;
79- var relationships = new List < GraphRelationship > ( ) ;
80- await foreach ( var relationship in graph . GetOutgoingRelationshipsAsync ( "alice" , token ) . ConfigureAwait ( false ) )
85+ services . AddKeyedSingleton < WorkflowDelegate > ( "neo4j-seed" , static ( _ , _ ) => async ( config , context , token ) =>
8186 {
82- relationships . Add ( relationship ) ;
83- }
87+ var graph = context . Services . GetRequiredKeyedService < IGraphStore > ( "neo4j" ) ;
88+ await graph . InitializeAsync ( token ) . ConfigureAwait ( false ) ;
89+ await graph . UpsertNodeAsync ( "alice" , "Person" , new Dictionary < string , object ? > { [ "name" ] = "Alice" } , token ) . ConfigureAwait ( false ) ;
90+ await graph . UpsertNodeAsync ( "bob" , "Person" , new Dictionary < string , object ? > { [ "name" ] = "Bob" } , token ) . ConfigureAwait ( false ) ;
91+ await graph . UpsertRelationshipAsync ( "alice" , "bob" , "KNOWS" , new Dictionary < string , object ? > { [ "since" ] = 2024 } , token ) . ConfigureAwait ( false ) ;
92+ var relationships = new List < GraphRelationship > ( ) ;
93+ await foreach ( var relationship in graph . GetOutgoingRelationshipsAsync ( "alice" , token ) . ConfigureAwait ( false ) )
94+ {
95+ relationships . Add ( relationship ) ;
96+ }
8497
85- context . Items [ "neo4j:relationship-count" ] = relationships . Count ;
86- return new WorkflowResult ( null ) ;
87- } ) ;
98+ context . Items [ "neo4j:relationship-count" ] = relationships . Count ;
99+ return new WorkflowResult ( null ) ;
100+ } ) ;
88101
89- services . AddKeyedSingleton < WorkflowDelegate > ( "postgres-seed" , static ( _ , _ ) => async ( config , context , token ) =>
90- {
91- var graph = context . Services . GetRequiredKeyedService < IGraphStore > ( "postgres" ) ;
92- await graph . InitializeAsync ( token ) . ConfigureAwait ( false ) ;
93- await graph . UpsertNodeAsync ( "chapter-1" , "Chapter" , new Dictionary < string , object ? > { [ "title" ] = "Origins" } , token ) . ConfigureAwait ( false ) ;
94- await graph . UpsertNodeAsync ( "chapter-2" , "Chapter" , new Dictionary < string , object ? > { [ "title" ] = "Discovery" } , token ) . ConfigureAwait ( false ) ;
95- await graph . UpsertRelationshipAsync ( "chapter-1" , "chapter-2" , "LEADS_TO" , new Dictionary < string , object ? > { [ "weight" ] = 0.9 } , token ) . ConfigureAwait ( false ) ;
96- var relationships = new List < GraphRelationship > ( ) ;
97- await foreach ( var relationship in graph . GetOutgoingRelationshipsAsync ( "chapter-1" , token ) . ConfigureAwait ( false ) )
102+ services . AddKeyedSingleton < WorkflowDelegate > ( "postgres-seed" , static ( _ , _ ) => async ( config , context , token ) =>
98103 {
99- relationships . Add ( relationship ) ;
100- }
104+ var graph = context . Services . GetRequiredKeyedService < IGraphStore > ( "postgres" ) ;
105+ await graph . InitializeAsync ( token ) . ConfigureAwait ( false ) ;
106+ await graph . UpsertNodeAsync ( "chapter-1" , "Chapter" , new Dictionary < string , object ? > { [ "title" ] = "Origins" } , token ) . ConfigureAwait ( false ) ;
107+ await graph . UpsertNodeAsync ( "chapter-2" , "Chapter" , new Dictionary < string , object ? > { [ "title" ] = "Discovery" } , token ) . ConfigureAwait ( false ) ;
108+ await graph . UpsertRelationshipAsync ( "chapter-1" , "chapter-2" , "LEADS_TO" , new Dictionary < string , object ? > { [ "weight" ] = 0.9 } , token ) . ConfigureAwait ( false ) ;
109+ var relationships = new List < GraphRelationship > ( ) ;
110+ await foreach ( var relationship in graph . GetOutgoingRelationshipsAsync ( "chapter-1" , token ) . ConfigureAwait ( false ) )
111+ {
112+ relationships . Add ( relationship ) ;
113+ }
101114
102- context . Items [ "postgres:relationship-count" ] = relationships . Count ;
103- return new WorkflowResult ( null ) ;
104- } ) ;
115+ context . Items [ "postgres:relationship-count" ] = relationships . Count ;
116+ return new WorkflowResult ( null ) ;
117+ } ) ;
118+
119+ services . AddNeo4jGraphStore ( "neo4j" , options =>
120+ {
121+ options . Uri = boltEndpoint . ToString ( ) ;
122+ options . Username = "neo4j" ;
123+ options . Password = Neo4jPassword ;
124+ } , makeDefault : true ) ;
125+
126+ services . AddPostgresGraphStore ( "postgres" , options =>
127+ {
128+ options . ConnectionString = postgresConnection ! ;
129+ options . GraphName = "graphrag" ;
130+ } ) ;
131+ }
105132
106133 if ( includeCosmos )
107134 {
@@ -123,19 +150,6 @@ public async Task InitializeAsync()
123150 } ) ;
124151 }
125152
126- services . AddNeo4jGraphStore ( "neo4j" , options =>
127- {
128- options . Uri = boltEndpoint . ToString ( ) ;
129- options . Username = "neo4j" ;
130- options . Password = Neo4jPassword ;
131- } , makeDefault : true ) ;
132-
133- services . AddPostgresGraphStore ( "postgres" , options =>
134- {
135- options . ConnectionString = postgresConnection ;
136- options . GraphName = "graphrag" ;
137- } ) ;
138-
139153 if ( includeCosmos )
140154 {
141155 services . AddCosmosGraphStore ( "cosmos" , options =>
0 commit comments