improve table create
This commit is contained in:
parent
08289c4d43
commit
748e48bdf5
@ -1,55 +1,11 @@
|
|||||||
import embedding
|
import lancedb, pyarrow
|
||||||
|
import config
|
||||||
import lancedb
|
db = lancedb.connect(config.memories_db_path)
|
||||||
|
schema = pyarrow.schema([
|
||||||
url = "http://localhost:11434/api/embed"
|
pyarrow.field( 'id', pyarrow.string() ),
|
||||||
model = "nomic-embed-text"
|
pyarrow.field( 'title', pyarrow.string() ),
|
||||||
text = "Saya lupa password di HRIS AFMS2"
|
pyarrow.field( 'story', pyarrow.string() ),
|
||||||
|
pyarrow.field( 'vector_title', pyarrow.list_( pyarrow.float32(), config.memories_vector_size ) ),
|
||||||
memories_db_path = "./memories"
|
])
|
||||||
memories_table = "knowledge_stories"
|
db.create_table(config.memories_table, schema=schema)
|
||||||
|
print(f'Table "{config.memories_table}" berhasil diproses.')
|
||||||
docs = [
|
|
||||||
{
|
|
||||||
"id": "wifi-001",
|
|
||||||
"title": "Perubahan password WiFi menjadi login portal",
|
|
||||||
"story": (
|
|
||||||
"Password WiFi kantor telah berubah. "
|
|
||||||
"Sekarang akses WiFi menggunakan login portal. "
|
|
||||||
"Akun login akan diberikan melalui chat pribadi masing-masing user."
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "m365-001",
|
|
||||||
"title": "Cara cek spam pada Outlook Group",
|
|
||||||
"story": (
|
|
||||||
"Untuk mengecek spam pada Outlook Group, buka Outlook Web. "
|
|
||||||
"Masuk ke menu Groups, pilih group terkait, lalu cek folder Junk Email atau Spam."
|
|
||||||
),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "printer-001",
|
|
||||||
"title": "Printer tidak terdeteksi di komputer",
|
|
||||||
"story": (
|
|
||||||
"Jika printer tidak terdeteksi, cek koneksi kabel atau jaringan. "
|
|
||||||
"Pastikan driver printer sudah terinstall, lalu coba restart service Print Spooler."
|
|
||||||
),
|
|
||||||
},
|
|
||||||
]
|
|
||||||
|
|
||||||
rows = []
|
|
||||||
for doc in docs:
|
|
||||||
row = {
|
|
||||||
"id": doc["id"],
|
|
||||||
"title": doc["title"],
|
|
||||||
"story": doc["story"],
|
|
||||||
"vector_title": embedding.embed_text(doc["title"]),
|
|
||||||
}
|
|
||||||
rows.append(row)
|
|
||||||
|
|
||||||
db = lancedb.connect(memories_db_path)
|
|
||||||
table = db.create_table(memories_table, data=rows, mode="overwrite")
|
|
||||||
|
|
||||||
print("Table berhasil dibuat.")
|
|
||||||
print("Nama table:", memories_table)
|
|
||||||
print("Jumlah row:", table.count_rows())
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user