Skip to content

Instantly share code, notes, and snippets.

@jasonbosco
Created June 28, 2024 16:40
Show Gist options
  • Save jasonbosco/70a045c4f292fe150ae4aeaf4caea326 to your computer and use it in GitHub Desktop.
Save jasonbosco/70a045c4f292fe150ae4aeaf4caea326 to your computer and use it in GitHub Desktop.
docker run -p 8108:8108 \
-v"$(pwd)"/typesense-data:/data typesense/typesense:26.0 \
--data-dir /data \
--enable-search-analytics=true \
--analytics-dir=/data \
--analytics-flush-interval=60 \
--api-key=$TYPESENSE_API_KEY \
--enable-cors
export TYPESENSE_API_KEY=xyz
curl -k "http://localhost:8108/analytics/rules" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"name": "product_queries_aggregation",
"type": "popular_queries",
"params": {
"source": {
"collections": ["products"]
},
"destination": {
"collection": "product_queries"
},
"limit": 1000
}
}'
curl -k "http://localhost:8108/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"name": "product_queries",
"fields": [
{"name": "q", "type": "string" },
{"name": "count", "type": "int32" }
]
}'
curl -k "http://localhost:8108/collections" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"name": "products",
"fields": [
{"name": "name", "type": "string" },
{"name": "description", "type": "string" },
{
"name": "embedding",
"type": "float[]",
"embed": {
"from": [
"name",
"description"
],
"model_config": {
"model_name": "ts/all-MiniLM-L12-v2"
}
}
}
]
}'
curl -k "http://localhost:8108/collections/products/documents/import" \
-X POST \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{"name": "Testing 1", "description": "testing 1"}
{"name": "Testing 2", "description": "testing 2"}'
curl -k "http://localhost:8108/multi_search" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"searches": [
{
"q": "testing",
"query_by": "embedding",
"collection": "products"
}
]
}'
curl -k "http://localhost:8108/multi_search" \
-X POST \
-H "Content-Type: application/json" \
-H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" \
-d '{
"searches": [
{
"q": "*",
"collection": "product_queries"
}
]
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment