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

Function init

LightRAG/examples/lightrag_api_oracle_demo..py:82–129  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

80
81
82async def init():
83 # Detect embedding dimension
84 embedding_dimension = await get_embedding_dim()
85 print(f"Detected embedding dimension: {embedding_dimension}")
86 # Create Oracle DB connection
87 # The `config` parameter is the connection configuration of Oracle DB
88 # More docs here https://python-oracledb.readthedocs.io/en/latest/user_guide/connection_handling.html
89 # We storage data in unified tables, so we need to set a `workspace` parameter to specify which docs we want to store and query
90 # Below is an example of how to connect to Oracle Autonomous Database on Oracle Cloud
91
92 oracle_db = OracleDB(
93 config={
94 "user": "",
95 "password": "",
96 "dsn": "",
97 "config_dir": "path_to_config_dir",
98 "wallet_location": "path_to_wallet_location",
99 "wallet_password": "wallet_password",
100 "workspace": "company",
101 } # specify which docs you want to store and query
102 )
103
104 # Check if Oracle DB tables exist, if not, tables will be created
105 await oracle_db.check_tables()
106 # Initialize LightRAG
107 # We use Oracle DB as the KV/vector/graph storage
108 # You can add `addon_params={"example_number": 1, "language": "Simplfied Chinese"}` to control the prompt
109 rag = LightRAG(
110 enable_llm_cache=False,
111 working_dir=WORKING_DIR,
112 chunk_token_size=512,
113 llm_model_func=llm_model_func,
114 embedding_func=EmbeddingFunc(
115 embedding_dim=embedding_dimension,
116 max_token_size=512,
117 func=embedding_func,
118 ),
119 graph_storage="OracleGraphStorage",
120 kv_storage="OracleKVStorage",
121 vector_storage="OracleVectorDBStorage",
122 )
123
124 # Setthe KV/vector/graph storage's `db` property, so all operation will use same connection pool
125 rag.graph_storage_cls.db = oracle_db
126 rag.key_string_value_json_storage_cls.db = oracle_db
127 rag.vector_db_storage_cls.db = oracle_db
128
129 return rag
130
131
132# Extract and Insert into LightRAG storage

Callers 1

lifespanFunction · 0.85

Calls 5

check_tablesMethod · 0.95
OracleDBClass · 0.90
LightRAGClass · 0.90
EmbeddingFuncClass · 0.90
get_embedding_dimFunction · 0.70

Tested by

no test coverage detected