Updating
This commit is contained in:
parent
de01227c5d
commit
dfa9090198
@ -1,5 +1,6 @@
|
||||
model_url = "http://localhost:11434/api/embed"
|
||||
model_name = "nomic-embed-text"
|
||||
memories_db_path = "./memories"
|
||||
memories_table = "knowledge_stories"
|
||||
|
||||
memories_db_path = "./ragroleplay"
|
||||
memories_vector_size = 768
|
||||
|
||||
|
||||
@ -1,28 +1,22 @@
|
||||
import gc, sys, lancedb
|
||||
import config, embedding
|
||||
import config, lib.ragroleplay as ragroleplay
|
||||
|
||||
def main():
|
||||
def memories_check(question, search_limit):
|
||||
db = lancedb.connect(config.memories_db_path)
|
||||
table = db.open_table(config.memories_table)
|
||||
question = sys.argv[1]
|
||||
query_vector = embedding.embed_text(config.model_url, config.model_name, question)
|
||||
table = db.open_table("knowledge_memories")
|
||||
query_vector = ragroleplay.embed_text(config.model_url, config.model_name, question)
|
||||
results = table.search(query_vector, vector_column_name="vector_context").limit(search_limit).to_list()
|
||||
|
||||
results = (
|
||||
table.search(query_vector, vector_column_name="vector_context")
|
||||
.limit(3)
|
||||
.to_list()
|
||||
)
|
||||
|
||||
print("\n" + "=" * 60)
|
||||
print("")
|
||||
print(f"Pertanyaan: {question}")
|
||||
print("=" * 60)
|
||||
print("")
|
||||
|
||||
if not results:
|
||||
print("Tidak ada memori yang ditemukan.")
|
||||
else:
|
||||
print(f"Ditemukan {len(results)} memori yang relevan berdasarkan KONTEKS:\n")
|
||||
for i, row in enumerate(results, 1):
|
||||
print(f"--- Memori #{i} ---")
|
||||
print(f"Memori #{i}")
|
||||
print(f"Kapan: {row['relative_time']}")
|
||||
print(f"Kejadian: {row['event']}")
|
||||
print(f"Detail: {row['detail']}")
|
||||
@ -30,13 +24,11 @@ def main():
|
||||
print(f"Emosi: {row['emotional']}")
|
||||
print(f"Kategori: {row['category']}")
|
||||
print(f"Skor Jarak: {row.get('_distance', 'N/A')}")
|
||||
print("-" * 30)
|
||||
|
||||
print("=" * 60)
|
||||
print("")
|
||||
|
||||
del table
|
||||
del db
|
||||
gc.collect()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
memories_check(sys.argv[1], 3)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import config, embedding
|
||||
text = "Saya lupa password di HRIS AFMS2"
|
||||
vector = embedding.embed_text(config.model_url, config.model_name, text)
|
||||
import config, lib.ragroleplay as ragroleplay
|
||||
text = "Saya lupa password"
|
||||
vector = ragroleplay.embed_text(config.model_url, config.model_name, text)
|
||||
print("Text:")
|
||||
print(text)
|
||||
print("Vector:")
|
||||
|
||||
@ -1,23 +1,4 @@
|
||||
import gc, lancedb, pyarrow
|
||||
import config
|
||||
|
||||
def main():
|
||||
db = lancedb.connect(config.memories_db_path)
|
||||
schema = pyarrow.schema([
|
||||
pyarrow.field('id', pyarrow.uuid(), metadata={'description': 'Unique identifier (UUID)'}),
|
||||
pyarrow.field('timestamp', pyarrow.timestamp('ms'), metadata={'description': 'When record created'}),
|
||||
pyarrow.field('relative_time', pyarrow.string(), metadata={'description': 'Explaining when it happen'}),
|
||||
pyarrow.field('event', pyarrow.string(), metadata={'description': 'What event'}),
|
||||
pyarrow.field('category', pyarrow.string(), metadata={'description': 'Event category'}),
|
||||
pyarrow.field('detail', pyarrow.string(), metadata={'description': 'Event detail'}),
|
||||
pyarrow.field('physical', pyarrow.string(), metadata={'description': 'Character physical state'}),
|
||||
pyarrow.field('emotional', pyarrow.string(), metadata={'description': 'Character emotional state'}),
|
||||
pyarrow.field('vector_context', pyarrow.list_(pyarrow.float32(), config.memories_vector_size)),
|
||||
])
|
||||
db.create_table(config.memories_table, schema=schema)
|
||||
print(f'Table "{config.memories_table}" berhasil diproses.')
|
||||
del db
|
||||
gc.collect()
|
||||
import config, lib.ragroleplay as ragroleplay
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
ragroleplay.create_table(config.memories_db_path, config.memories_vector_size)
|
||||
|
||||
@ -1,10 +1,10 @@
|
||||
import gc, lancedb, uuid
|
||||
from datetime import datetime, timedelta
|
||||
import config, embedding
|
||||
import config, lib.ragroleplay as ragroleplay
|
||||
|
||||
def main():
|
||||
db = lancedb.connect(config.memories_db_path)
|
||||
table = db.open_table(config.memories_table)
|
||||
table = db.open_table("knowledge_memories")
|
||||
now = datetime.now()
|
||||
|
||||
memories = [
|
||||
@ -121,13 +121,13 @@ def main():
|
||||
"detail": mem["detail"],
|
||||
"physical": mem["physical"],
|
||||
"emotional": mem["emotional"],
|
||||
"vector_context": embedding.embed_text(config.model_url, config.model_name, context_text),
|
||||
"vector_context": ragroleplay.embed_text(config.model_url, config.model_name, context_text),
|
||||
}
|
||||
table.add([row])
|
||||
print(f"Menambahkan memori: {mem['event']}")
|
||||
|
||||
print("\nTable memori roleplaying dengan vector_context berhasil diproses.")
|
||||
print("Nama table:", config.memories_table)
|
||||
print("Nama table: knowledge_memories")
|
||||
print("Jumlah row:", table.count_rows())
|
||||
|
||||
del table
|
||||
|
||||
Loading…
Reference in New Issue
Block a user