Skip to content

Commit 27ec1f5

Browse files
committed
update sample
1 parent ba89406 commit 27ec1f5

File tree

2 files changed

+23
-23
lines changed

2 files changed

+23
-23
lines changed

examples/llamaIndex/llamaIndex_dbreader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@
3030
print(type(db_reader.sql_database.run_sql))
3131
# SQLDatabase available properties:
3232
print(type(db_reader.sql_database.dialect))
33-
print(type(db_reader.sql_database.engine))
33+
print(type(db_reader.sql_database.engine))

examples/llamaIndex/llamaIndex_vectorstore.py

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
77
"""
88

9+
from llama_index.core.vector_stores.types import ExactMatchFilter, MetadataFilters
10+
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageContext
11+
import timeplus_connect
12+
import os
913
import importlib
1014
import json
1115
import logging
@@ -48,7 +52,8 @@ def escape_str(value: str) -> str:
4852
BS = "\\"
4953
must_escape = (BS, "'")
5054
return (
51-
"".join(f"{BS}{c}" if c in must_escape else c for c in value) if value else ""
55+
"".join(
56+
f"{BS}{c}" if c in must_escape else c for c in value) if value else ""
5257
)
5358

5459

@@ -226,7 +231,8 @@ def __init__(
226231
self._column_config = column_config
227232
self._column_names = column_names
228233
self._column_type_names = column_type_names
229-
dimension = len(Settings.embed_model.get_query_embedding("try this out"))
234+
dimension = len(
235+
Settings.embed_model.get_query_embedding("try this out"))
230236
self.create_table(dimension)
231237

232238
@property
@@ -254,7 +260,8 @@ def _upload_batch(
254260
for idx, item in enumerate(batch):
255261
_row = []
256262
for column_name in self._column_names:
257-
_row.append(self._column_config[column_name]["extract_func"](item))
263+
_row.append(
264+
self._column_config[column_name]["extract_func"](item))
258265
_data.append(_row)
259266

260267
self._client.insert(
@@ -264,11 +271,10 @@ def _upload_batch(
264271
column_type_names=self._column_type_names,
265272
)
266273

267-
268274
def _append_meta_filter_condition(
269275
self, where_str: Optional[str], exact_match_filter: list
270276
) -> str:
271-
277+
272278
filter_str = " AND ".join(
273279
f"json_extract_string("
274280
f"{self.metadata_column}, '{filter_item.key}') "
@@ -354,13 +360,13 @@ def query(
354360
nodes = []
355361
ids = []
356362
similarities = []
357-
#print(f"query: {query_statement}")
363+
# print(f"query: {query_statement}")
358364
response = self._client.query(query_statement)
359-
#print(f"response: {response}")
365+
# print(f"response: {response}")
360366
column_names = response.column_names
361-
#print(f"column_names: {column_names}")
362-
#print(f"column_names: {response.result_columns}")
363-
367+
# print(f"column_names: {column_names}")
368+
# print(f"column_names: {response.result_columns}")
369+
364370
id_idx = column_names.index("id")
365371
text_idx = column_names.index("text")
366372
metadata_idx = column_names.index("metadata")
@@ -388,26 +394,21 @@ def query(
388394
similarities.append(r[score_idx])
389395
ids.append(r[id_idx])
390396
return VectorStoreQueryResult(nodes=nodes, similarities=similarities, ids=ids)
391-
392397

393-
# test code
394-
import os
395-
import timeplus_connect
396398

397-
from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, StorageContext
398-
from llama_index.core.vector_stores.types import ExactMatchFilter, MetadataFilters
399+
# test code
399400

400401

401402
timeplus_host = os.getenv("TIMEPLUS_HOST") or "localhost"
402403
timeplus_user = os.getenv("TIMEPLUS_USER") or "proton"
403404
timeplus_password = os.getenv("TIMEPLUS_PASSWORD") or "timeplus@t+"
404405

405406
client = timeplus_connect.get_client(
406-
host=timeplus_host,
407-
port=8123,
408-
username=timeplus_user,
409-
password=timeplus_password,
410-
)
407+
host=timeplus_host,
408+
port=8123,
409+
username=timeplus_user,
410+
password=timeplus_password,
411+
)
411412

412413
# Load documents and build index
413414
documents = SimpleDirectoryReader(
@@ -444,4 +445,3 @@ def query(
444445
)
445446
response = query_engine.query("what did the author do growing up?")
446447
print(response)
447-

0 commit comments

Comments
 (0)