chroma go
v0.1.4
이동 중에 작성된 간단한 Chroma 벡터 데이터베이스 클라이언트
Chroma 버전과 함께 작동합니다 : v0.4.3 -v0.5.x
보다 심층적 인 정보를 얻으려면 사용자가 도서관의 문서 사이트를 방문하도록 초대합니다. Chroma Go Docs
0.2.0 +이후 ONNX 런타임 (ORT)에서 실행되는 기본 all-MiniLM-L6-v2 모델도 지원합니다. 릴리스 0.2.0 에서 Chroma Go 클라이언트는 또한 재고 기능을 지원합니다. 다음은 지원됩니다.
중요한
아래에 문서화 된 바와 같이 v0.2.0 까지 이어지는 많은 새로운 변경 사항이 있습니다. 사용하려면 최신 버전의 클라이언트를 설치하십시오.
go get github.com/amikos-tech/chroma-go@maingo get github.com/amikos-tech/chroma-go수입:
import (
chroma "github.com/amikos-tech/chroma-go"
)크로마 실행의 실행중인 인스턴스가 있는지 확인하십시오. 다음 두 가지 옵션 중 하나를 권장합니다.
Docker , minikube 및 kubectl 설치해야합니다).설정 (Cloud-Native) :
minikube start --profile chromago
minikube profile chromago
helm repo add chroma https://amikos-tech.github.io/chromadb-chart/
helm repo update
helm install chroma chroma/chromadb --set chromadb.allowReset=true,chromadb.apiVersion=0.4.5 | 참고 : Minikube 클러스터를 삭제하려면 : minikube delete --profile chromago
다음 예를 고려하십시오.
package main
import (
"context"
"fmt"
"log"
"os"
chroma "github.com/amikos-tech/chroma-go"
"github.com/amikos-tech/chroma-go/collection"
openai "github.com/amikos-tech/chroma-go/pkg/embeddings/openai"
"github.com/amikos-tech/chroma-go/types"
)
func main () {
// Create a new Chroma client
client , err := chroma . NewClient ( chroma . WithBasePath ( "http://localhost:8000" ))
if err != nil {
log . Fatalf ( "Error creating client: %s n " , err )
return
}
// Close the client to release any resources such as local embedding functions
defer func () {
err = client . Close ()
if err != nil {
log . Fatalf ( "Error closing client: %s n " , err )
}
}()
// Create a new collection with options. We don't provide an embedding function here, so the default embedding function will be used
newCollection , err := client . NewCollection (
context . TODO (),
"test-collection" ,
collection . WithMetadata ( "key1" , "value1" ),
collection . WithHNSWDistanceFunction ( types . L2 ),
)
if err != nil {
log . Fatalf ( "Error creating collection: %s n " , err )
}
// Create a new record set with to hold the records to insert
rs , err := types . NewRecordSet (
types . WithEmbeddingFunction ( newCollection . EmbeddingFunction ), // we pass the embedding function from the collection
types . WithIDGenerator ( types . NewULIDGenerator ()),
)
if err != nil {
log . Fatalf ( "Error creating record set: %s n " , err )
}
// Add a few records to the record set
rs . WithRecord ( types . WithDocument ( "My name is John. And I have two dogs." ), types . WithMetadata ( "key1" , "value1" ))
rs . WithRecord ( types . WithDocument ( "My name is Jane. I am a data scientist." ), types . WithMetadata ( "key2" , "value2" ))
// Build and validate the record set (this will create embeddings if not already present)
_ , err = rs . BuildAndValidate ( context . TODO ())
if err != nil {
log . Fatalf ( "Error validating record set: %s n " , err )
}
// Add the records to the collection
_ , err = newCollection . AddRecords ( context . Background (), rs )
if err != nil {
log . Fatalf ( "Error adding documents: %s n " , err )
}
// Count the number of documents in the collection
countDocs , qrerr := newCollection . Count ( context . TODO ())
if qrerr != nil {
log . Fatalf ( "Error counting documents: %s n " , qrerr )
}
// Query the collection
fmt . Printf ( "countDocs: %v n " , countDocs ) //this should result in 2
qr , qrerr := newCollection . Query ( context . TODO (), [] string { "I love dogs" }, 5 , nil , nil , nil )
if qrerr != nil {
log . Fatalf ( "Error querying documents: %s n " , qrerr )
}
fmt . Printf ( "qr: %v n " , qr . Documents [ 0 ][ 0 ]) //this should result in the document about dogs
}make buildmake testmake generate make lint-fix참고 : Docker를 설치해야합니다
make server