Cơ sở dữ liệu Vector và LLMs (phần 32)

Các cách thức khác nhau để load ChromaDB

Trong ví dụ, bạn đã tạo một CSDL ChromaDB mới. Hơn nữa, nếu đã có một cái đã tồn tại từ test trước, nó sẽ bị xóa
và một cái mới được tạo.
Như bạn đã có thể nghi ngờ, mode hoạt động này là không lí tưởng cho các môi trường sản suất. Cách tiếp cận thông
lệ hơn sẽ là sử dụng một CSDL hiện có và giành bất cứ bộ nào nó có thể chứa. Cách thức nhất để giành cái này là
bằng cách sử dụng thư mục cố định bạn chỉ ra để tạo CSDL, chính sử dụng hàm PersistentClient để khởi tạo thực thể
một máy khách.

chroma_client_2 = chromadb.PersistentClient(path=”/content/drive/MyDrive/chromadb”)

Sau khi giành máy khách, bạn có thể giành các bộ đơn giản bằng cách sử dụng các tên của chúng. Một khi bạn đã có
object bộ, bạn có thể bắt đầu bằng cách sử dụng nó như bạn đã làm trong ví dụ trước.

collection2 = chroma_client_2.get_collection(name=collection_name)
results2 = collection.query(query_texts=[“laptop”], n_results=10 )
print(results)
{‘ids’: [[‘id173’, ‘id829’, ‘id117’, ‘id535’, ‘id141’, ‘id218’, ‘id390’, ‘id273’, ‘id56’, ‘id900’]], ‘distances’: [[0.8593594431877136, 1.0294400453567505, 1.0793331861495972, 1.093001127243042, 1.1329681873321533, 1.2130440473556519, 1.214331865310669, 1.2164140939712524, 1.2220635414123535, 1.2754170894622803]], ‘metadatas’: [[{‘topic’: ‘TECHNOLOGY’}, {‘topic’: ‘TECHNOLOGY’}, {‘topic’: ‘TECHNOLOGY’}, {‘topic’: ‘TECHNOLOGY’}, {‘topic’: ‘TECHNOLOGY’}, {‘topic’: ‘TECHNOLOGY’}, {‘topic’: ‘TECHNOLOGY’}, {‘topic’: ‘TECHNOLOGY’}, {‘topic’: ‘TECHNOLOGY’}, {‘topic’: ‘TECHNOLOGY’}]], ’embeddings’: None, ‘documents’: [[‘The Legendary Toshiba is Officially Done With Making Laptops’, ‘3 gaming laptop deals you can’t afford to miss today’, ‘Lenovo and HP control half of the global laptop market’, ‘Asus ROG Zephyrus G14 gaming laptop announced in India’, ‘Acer Swift 3 featuring a 10th-generation Intel Ice Lake CPU, 2K screen, and more launched in India for INR 64999 (US$865)’, “Apple’s Next MacBook Could Be the Cheapest in Company’s History”, “Features of Huawei’s Desktop Computer Revealed”, ‘Redmi to launch its first gaming laptop on August 14: Here are all the details’, ‘Toshiba shuts the lid on laptops after 35 years’, ‘This is the cheapest Windows PC by a mile and it even has a spare SSD slot’]], ‘uris’: None, ‘data’: None}

Bạn sẽ thấy code này tại cuối của notebook 2_1_Vector_Databases_LLMs.ipynb.
Code hỗ trợ là có sẵn qua trang sản phẩm, nằm tại https://github.com/Apress/Large-Language-Models-Projects

Chia sẻ