First stable
This commit is contained in:
parent
748e48bdf5
commit
d4dea3bc0a
3
.gitignore
vendored
Normal file
3
.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
**/__pycache__/
|
||||||
|
*.py[cod]
|
||||||
|
*$py.class
|
||||||
5
config.py
Normal file
5
config.py
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
model_url = "http://localhost:11434/api/embed"
|
||||||
|
model_name = "nomic-embed-text"
|
||||||
|
memories_db_path = "./memories"
|
||||||
|
memories_table = "knowledge_stories"
|
||||||
|
memories_vector_size = 768
|
||||||
20
memories_semantic_search.py
Normal file
20
memories_semantic_search.py
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import lancedb
|
||||||
|
import config, embedding
|
||||||
|
db = lancedb.connect(config.memories_db_path)
|
||||||
|
table = db.open_table(config.memories_table)
|
||||||
|
question = "Email group Microsoft tidak muncul, apakah masuk spam?"
|
||||||
|
query_vector = embedding.embed_text(question)
|
||||||
|
results = (
|
||||||
|
table.search(query_vector, vector_column_name="vector_title")
|
||||||
|
.limit(3)
|
||||||
|
.to_list()
|
||||||
|
)
|
||||||
|
print("Pertanyaan:")
|
||||||
|
print(question)
|
||||||
|
print("Hasil paling mirip:")
|
||||||
|
for row in results:
|
||||||
|
print("=" * 60)
|
||||||
|
print("ID:", row["id"])
|
||||||
|
print("Title:", row["title"])
|
||||||
|
print("Story:", row["story"])
|
||||||
|
print("Distance:", row["_distance"])
|
||||||
7
memories_test.py
Normal file
7
memories_test.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import config, embedding
|
||||||
|
text = "Saya lupa password di HRIS AFMS2"
|
||||||
|
vector = embedding.embed_text(config.model_url, config.model_name, text)
|
||||||
|
print("Text:")
|
||||||
|
print(text)
|
||||||
|
print("Vector:")
|
||||||
|
print(str(vector))
|
||||||
2
requirements.txt
Normal file
2
requirements.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
lancedb
|
||||||
|
pyarrow
|
||||||
43
table_modify.py
Normal file
43
table_modify.py
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
import lancedb
|
||||||
|
import embedding
|
||||||
|
db = lancedb.connect(config.memories_db_path)
|
||||||
|
table = db.open_table(config.memories_table)
|
||||||
|
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."
|
||||||
|
),
|
||||||
|
},
|
||||||
|
]
|
||||||
|
for doc in docs:
|
||||||
|
row = {
|
||||||
|
"id" : doc["id" ],
|
||||||
|
"title" : doc["title" ],
|
||||||
|
"story" : doc["story" ],
|
||||||
|
"vector_title" : embedding.embed_text(doc["title"]),
|
||||||
|
}
|
||||||
|
table.add([row])
|
||||||
|
print(f"Menambahkan record: {doc['title']}")
|
||||||
|
print("\nTable berhasil diproses.")
|
||||||
|
print("Nama table:", config.memories_table)
|
||||||
|
print("Jumlah row:", table.count_rows())
|
||||||
Loading…
Reference in New Issue
Block a user