Clojure library for Milvus.
com.constacts/milvus-clj {:mvn/version "0.2.8"}
(require '[milvus-clj.core :as milvus])
(def client (milvus/client {:host "localhost" :port 19530 :database "mydb"}))
(milvus/create-collection client {:collection-name "mycoll"
:description "a collection for search"
:field-types [{:primary-key? true
:auto-id? false
:data-type :int64
:name "uid"
:description "unique id"}
{:data-type :float-vector
:name "embedding"
:description "embeddings"
:dimension 3}]})
(milvus/create-index client {:collection-name "mycoll"
:field-name "embedding"
:index-type :flat
:index-name "embedding_index"
:metric-type :l2})
(milvus/load-collection client {:collection-name "mycoll"})
(milvus/insert client {:collection-name "mycoll"
:fields [{:name "uid" :values [1 2]}
{:name "embedding" :values [(map float [0.1 0.2 0.3])
(map float [0.4 0.5 0.6])]}]}
;; or
(milvus/insert client {:collection-name "mycoll"
:rows [{:uid 1
:embedding (map float [0.1 0.2 0.3])}
{:uid 2
:embedding (map float [0.4 0.5 0.6])}]})
;; for json type
(milvus/insert client {:collection-name "mycoll"
:rows [{:uid 1
:etc {:filename "README.md"}}]})
(milvus/delete client {:collection-name "mycoll"
:expr "uid == 1"})
(milvus/search client {:collection-name "mycoll"
:metric-type :l2
:vectors [(map float [0.3 0.4 0.5])
(map float [0.1 0.2 0.3])]
:vector-field-name "embedding"
:out-fields ["uid" "embedding"]
:top-k 2})
(milvus/hybrid-search client {:collection-name "mycoll"
:search-requests [{:vector-field-name "dense_vector"
:metric-type :l2
:float-vectors [(gen-float-vector 10)]
:top-k 10}
{:vector-field-name "sparse_vector"
:metric-type :ip
:sparse-float-vectors [(gen-sparse)]
:top-k 10}]
:out-fields ["pk" "dense_vector" "sparse_vector"]
:ranker {:type :weighted
:weights [0.7 0.3]}
:top-k 5}))
(milvus/query client {:collection-name "mycoll"
:expr "uid == 2"
:out-fields ["uid" "embedding"]})
(milvus/drop-index client {:collection-name "mycoll"
:index-name "embedding_index"})
(milvus/drop-collection client "mycoll")
(milvus/release-collection client {:collection-name "mycoll"})
Can you improve this documentation? These fine people already did:
Todd Eunmin Kim & Eunmin KimEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close