Skip to content

Commit

Permalink
ts2
Browse files Browse the repository at this point in the history
  • Loading branch information
daveatweaviate committed Sep 13, 2024
1 parent 059ad73 commit fe0b9c2
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 100 deletions.
72 changes: 72 additions & 0 deletions _includes/code/howto/indexes/indexes-v2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// TODO: Configure as part of the test harness
// TODO: Needs tests


var DEBUG = true;

// Imports
import weaviate, { WeaviateClient } from 'weaviate-ts-client';

// Create client connection
function getClient(){
const client: WeaviateClient = weaviate.client({
scheme: 'http',
host: 'localhost:8080',
});

return client;
}

// Delete pre-existing collections
function deleteClass(client, className: string){
try {
client.schema.classDeleter().withClassName(className).do();
} catch (e) {
// ignore error if class doesn't exist
}
return true
}

//////////////////////////////
// ENABLE HNSW - COLLECTION //
//////////////////////////////

async function createHNSWCollection(client, className: string){
if(DEBUG) console.log("START HNSW: " + await client.schema.exists(className))
// START EnableHNSW
// Add this import line
// import { vectorizer, dataType, configure } from 'weaviate-client';

if(DEBUG) console.log("END HNSW: " + await client.schema.exists(className))
}

/////////////////////////////
/// AVOID TOP LEVEL AWAIT ///
/////////////////////////////

// Main
async function main(){
const className = "ConfigCollection";

const client = await getClient();
if(DEBUG) console.log(client) ;

if(DEBUG) console.log("START: " + await client.schema.exists(className))
deleteClass(client, className)
if(DEBUG) console.log("START +1: " + await client.schema.exists(className))

// Only one create can run at a time due to aynsc code
// Run enable HNSW collection code
deleteClass(client, className)
if(await client.schema.exists(className) != true){
createHNSWCollection(client, className);
}

// // Run multiple named vector collection code
// deleteClass(client, className)
// if(await client.schema.exists(className) != true){
// createMultiCollection(client, className);
// }
}

main()
100 changes: 0 additions & 100 deletions _includes/code/howto/indexes/indexes-v3 copy.ts

This file was deleted.

72 changes: 72 additions & 0 deletions indexes-v2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// TODO: Configure as part of the test harness
// TODO: Needs tests


var DEBUG = true;

// Imports
import weaviate, { WeaviateClient } from 'weaviate-ts-client';

// Create client connection
function getClient(){
const client: WeaviateClient = weaviate.client({
scheme: 'http',
host: 'localhost:8080',
});

return client;
}

// Delete pre-existing collections
function deleteClass(client, className: string){
try {
client.schema.classDeleter().withClassName(className).do();
} catch (e) {
// ignore error if class doesn't exist
}
return true
}

//////////////////////////////
// ENABLE HNSW - COLLECTION //
//////////////////////////////

async function createHNSWCollection(client, className: string){
if(DEBUG) console.log("START HNSW: " + await client.schema.exists(className))
// START EnableHNSW
// Add this import line
// import { vectorizer, dataType, configure } from 'weaviate-client';

if(DEBUG) console.log("END HNSW: " + await client.schema.exists(className))
}

/////////////////////////////
/// AVOID TOP LEVEL AWAIT ///
/////////////////////////////

// Main
async function main(){
const className = "ConfigCollection";

const client = await getClient();
if(DEBUG) console.log(client) ;

if(DEBUG) console.log("START: " + await client.schema.exists(className))
deleteClass(client, className)
if(DEBUG) console.log("START +1: " + await client.schema.exists(className))

// Only one create can run at a time due to aynsc code
// Run enable HNSW collection code
deleteClass(client, className)
if(await client.schema.exists(className) != true){
createHNSWCollection(client, className);
}

// // Run multiple named vector collection code
// deleteClass(client, className)
// if(await client.schema.exists(className) != true){
// createMultiCollection(client, className);
// }
}

main()

0 comments on commit fe0b9c2

Please sign in to comment.