MCPcopy Create free account
hub / github.com/NanGePlus/LightRAGTest / OracleDB

Class OracleDB

LightRAG/lightrag/kg/oracle_impl.py:20–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

18
19
20class OracleDB:
21 def __init__(self, config, **kwargs):
22 self.host = config.get("host", None)
23 self.port = config.get("port", None)
24 self.user = config.get("user", None)
25 self.password = config.get("password", None)
26 self.dsn = config.get("dsn", None)
27 self.config_dir = config.get("config_dir", None)
28 self.wallet_location = config.get("wallet_location", None)
29 self.wallet_password = config.get("wallet_password", None)
30 self.workspace = config.get("workspace", None)
31 self.max = 12
32 self.increment = 1
33 logger.info(f"Using the label {self.workspace} for Oracle Graph as identifier")
34 if self.user is None or self.password is None:
35 raise ValueError("Missing database user or password in addon_params")
36
37 try:
38 oracledb.defaults.fetch_lobs = False
39
40 self.pool = oracledb.create_pool_async(
41 user=self.user,
42 password=self.password,
43 dsn=self.dsn,
44 config_dir=self.config_dir,
45 wallet_location=self.wallet_location,
46 wallet_password=self.wallet_password,
47 min=1,
48 max=self.max,
49 increment=self.increment,
50 )
51 logger.info(f"Connected to Oracle database at {self.dsn}")
52 except Exception as e:
53 logger.error(f"Failed to connect to Oracle database at {self.dsn}")
54 logger.error(f"Oracle database error: {e}")
55 raise
56
57 def numpy_converter_in(self, value):
58 """Convert numpy array to array.array"""
59 if value.dtype == np.float64:
60 dtype = "d"
61 elif value.dtype == np.float32:
62 dtype = "f"
63 else:
64 dtype = "b"
65 return array.array(dtype, value)
66
67 def input_type_handler(self, cursor, value, arraysize):
68 """Set the type handler for the input data"""
69 if isinstance(value, np.ndarray):
70 return cursor.var(
71 oracledb.DB_TYPE_VECTOR,
72 arraysize=arraysize,
73 inconverter=self.numpy_converter_in,
74 )
75
76 def numpy_converter_out(self, value):
77 """Convert array.array to numpy array"""

Callers 2

initFunction · 0.90
mainFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected