@@ -51,6 +51,59 @@ def test_connection():
5151 print (f"✗ Connection failed: { str (e )} " )
5252 return None
5353
54+ def check_collection_stats (store ):
55+ """Check statistics for each collection including total chunks and latest insertion"""
56+ if not store :
57+ print ("Skipping collection stats check as connection failed" )
58+ return
59+
60+ print ("\n === Collection Statistics ===" )
61+
62+ collections = {
63+ "PDF Collection" : "pdf_documents" ,
64+ "Repository Collection" : "repository_documents" ,
65+ "Web Knowledge Base" : "web_documents" ,
66+ "General Knowledge" : "general_knowledge"
67+ }
68+
69+ for name , collection in collections .items ():
70+ try :
71+ # Get total count
72+ count = store .get_collection_count (collection )
73+ print (f"\n { name } :" )
74+ print (f"Total chunks: { count } " )
75+
76+ # Get latest insertion if collection is not empty
77+ if count > 0 :
78+ latest = store .get_latest_chunk (collection )
79+ print ("Latest chunk:" )
80+ print (f" Content: { latest ['content' ][:150 ]} ..." if len (latest ['content' ]) > 150 else f" Content: { latest ['content' ]} " )
81+
82+ # Print metadata
83+ if isinstance (latest ['metadata' ], str ):
84+ try :
85+ metadata = json .loads (latest ['metadata' ])
86+ except :
87+ metadata = {"source" : latest ['metadata' ]}
88+ else :
89+ metadata = latest ['metadata' ]
90+
91+ source = metadata .get ('source' , 'Unknown' )
92+ print (f" Source: { source } " )
93+
94+ # Print other metadata based on collection type
95+ if collection == "pdf_documents" and 'page' in metadata :
96+ print (f" Page: { metadata ['page' ]} " )
97+ elif collection == "repository_documents" and 'file_path' in metadata :
98+ print (f" File: { metadata ['file_path' ]} " )
99+ elif collection == "web_documents" and 'title' in metadata :
100+ print (f" Title: { metadata ['title' ]} " )
101+ else :
102+ print ("No chunks found in this collection." )
103+
104+ except Exception as e :
105+ print (f"Error checking { name } : { str (e )} " )
106+
54107def test_add_and_query (store , query_text = "machine learning" ):
55108 """Test adding simple data and querying it"""
56109 if not store :
@@ -109,6 +162,7 @@ def test_add_and_query(store, query_text="machine learning"):
109162def main ():
110163 parser = argparse .ArgumentParser (description = "Test Oracle DB Vector Store" )
111164 parser .add_argument ("--query" , default = "machine learning" , help = "Query to use for testing" )
165+ parser .add_argument ("--stats-only" , action = "store_true" , help = "Only show collection statistics without inserting test data" )
112166
113167 args = parser .parse_args ()
114168
@@ -146,8 +200,13 @@ def main():
146200 # Test connection
147201 store = test_connection ()
148202
149- # Test add and query functionality
150- test_add_and_query (store , args .query )
203+ # Check collection statistics
204+ check_collection_stats (store )
205+
206+ # If stats-only flag is not set, also test add and query functionality
207+ if not args .stats_only :
208+ # Test add and query functionality
209+ test_add_and_query (store , args .query )
151210
152211 print ("\n === Test Completed ===" )
153212
0 commit comments