1. Go to this page and download the library: Download helgesverre/chromadb library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
$chromadb = new \HelgeSverre\Chromadb\Chromadb(
token: 'test-token-chroma-local-dev',
host: 'http://localhost',
port: '8000'
);
// Create a new collection with optional metadata
$chromadb->collections()->create(
name: 'my_collection',
);
// Count the number of collections
$chromadb->collections()->count();
// Retrieve a specific collection by name
$chromadb->collections()->get(
collectionName: 'my_collection'
);
// Delete a collection by name
$chromadb->collections()->delete(
collectionName: 'my_collection'
);
// Update a collection's name and/or metadata
$chromadb->collections()->update(
collectionId: '3ea5a914-e2ab-47cb-b285-8e585c9af4f3',
newName: 'new_collection_name',
);
// Add items to a collection with optional embeddings, metadata, and documents
$chromadb->items()->add(
collectionId: '3ea5a914-e2ab-47cb-b285-8e585c9af4f3',
ids: ['item1', 'item2'],
embeddings: ['embedding1', 'embedding2'],
documents: ['doc1', 'doc2']
);
// Update items in a collection with new embeddings, metadata, and documents
$chromadb->items()->update(
collectionId: '3ea5a914-e2ab-47cb-b285-8e585c9af4f3',
ids: ['item1', 'item2'],
embeddings: ['new_embedding1', 'new_embedding2'],
documents: ['new_doc1', 'new_doc2']
);
// Upsert items in a collection (insert if not exist, update if exist)
$chromadb->items()->upsert(
collectionId: '3ea5a914-e2ab-47cb-b285-8e585c9af4f3',
ids: ['item'],
metadatas: [['title' => 'metadata']],
documents: ['document']
);
// Retrieve specific items from a collection by their IDs
$chromadb->items()->get(
collectionId: '3ea5a914-e2ab-47cb-b285-8e585c9af4f3',
ids: ['item1', 'item2']
);
// Delete specific items from a collection by their IDs
$chromadb->items()->delete(
collectionId: '3ea5a914-e2ab-47cb-b285-8e585c9af4f3',
ids: ['item1', 'item2']
);
// Count the number of items in a collection
$chromadb->items()->count(
collectionId: '3ea5a914-e2ab-47cb-b285-8e585c9af4f3'
);
// Query items in a collection based on embeddings, texts, and other filters
$chromadb->items()->query(
collectionId: '3ea5a914-e2ab-47cb-b285-8e585c9af4f3',
queryEmbeddings: [createTestVector(0.8)],
$blogPosts = [
[
'title' => 'Exploring Laravel',
'summary' => 'A deep dive into Laravel frameworks...',
'tags' => ['PHP', 'Laravel', 'Web Development']
],
[
'title' => 'Introduction to React',
'summary' => 'Understanding the basics of React and how it revolutionizes frontend development.',
'tags' => ['JavaScript', 'React', 'Frontend']
],
];