@@ -33,10 +33,10 @@ struct EmbeddingsObject: Decodable {
3333}
3434
3535func embed( texts: [ String ] , inputType: String , apiKey: String ) async throws -> [ String ] {
36- let url = URL ( string: " https://api.cohere.com/v1 /embed " ) !
36+ let url = URL ( string: " https://api.cohere.com/v2 /embed " ) !
3737 let data = ApiData (
3838 texts: texts,
39- model: " embed-english-v3 .0 " ,
39+ model: " embed-v4 .0 " ,
4040 inputType: inputType,
4141 embeddingTypes: [ " ubinary " ]
4242 )
@@ -65,7 +65,7 @@ try await withThrowingTaskGroup(of: Void.self) { taskGroup in
6565
6666 try await client. query ( " CREATE EXTENSION IF NOT EXISTS vector " )
6767 try await client. query ( " DROP TABLE IF EXISTS documents " )
68- try await client. query ( " CREATE TABLE documents (id serial PRIMARY KEY, content text, embedding bit(1024 )) " )
68+ try await client. query ( " CREATE TABLE documents (id serial PRIMARY KEY, content text, embedding bit(1536 )) " )
6969
7070 let input = [
7171 " The dog is barking " ,
@@ -74,12 +74,12 @@ try await withThrowingTaskGroup(of: Void.self) { taskGroup in
7474 ]
7575 let embeddings = try await embed ( texts: input, inputType: " search_document " , apiKey: apiKey)
7676 for (content, embedding) in zip ( input, embeddings) {
77- try await client. query ( " INSERT INTO documents (content, embedding) VALUES ( \( content) , \( embedding) ::bit(1024 )) " )
77+ try await client. query ( " INSERT INTO documents (content, embedding) VALUES ( \( content) , \( embedding) ::bit(1536 )) " )
7878 }
7979
8080 let query = " forest "
8181 let queryEmbedding = ( try await embed ( texts: [ query] , inputType: " search_query " , apiKey: apiKey) ) [ 0 ]
82- let rows = try await client. query ( " SELECT content FROM documents ORDER BY embedding <~> \( queryEmbedding) ::bit(1024 ) LIMIT 5 " )
82+ let rows = try await client. query ( " SELECT content FROM documents ORDER BY embedding <~> \( queryEmbedding) ::bit(1536 ) LIMIT 5 " )
8383 for try await row in rows {
8484 print ( row)
8585 }
0 commit comments