diff --git a/README.md b/README.md index 9c67a12..0c96927 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ You can overwrite values by creating and adding new records to a file `./config/ - [Semantic Kernel Blog: The Power of Persistent Memory with Semantic Kernel and Qdrant Vector Database](https://devblogs.microsoft.com/semantic-kernel/the-power-of-persistent-memory-with-semantic-kernel-and-qdrant-vector-database/) - [Qdrant Vector Search [Vector Database]](https://qdrant.tech/) +- [Qdrant .NET(C#) SDK](https://github.com/qdrant/qdrant-dotnet) - [Qdrant Integration with OpenAI](https://qdrant.tech/documentation/integrations/#openai) - [Azure Container Instances (ACI)](https://learn.microsoft.com/azure/container-instances/) - [Azure Kubernetes Service (AKS)](https://learn.microsoft.com/azure/aks/) diff --git a/samples/dotnet/csharp/get-started.ipynb b/samples/dotnet/csharp/get-started.ipynb new file mode 100644 index 0000000..e67477d --- /dev/null +++ b/samples/dotnet/csharp/get-started.ipynb @@ -0,0 +1,558 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
Restore sources
Installed Packages
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "#r \"nuget:Qdrant.Client,1.7.0\"" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "using Qdrant.Client;\n", + "using Qdrant.Client.Grpc;" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create client" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "var client = new QdrantClient(host: \"localhost\",port: 6334,https:false);" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Clean collections" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "var collections = await client.ListCollectionsAsync();" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "if(collections.Where(x => x.Contains(\"movie_collection\")).Count() > 0) \n", + " await client.DeleteCollectionAsync(\"movie_collection\");" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## List collections" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
[  ]
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "await client.ListCollectionsAsync()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Create collection" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "await client.CreateCollectionAsync(\"movie_collection\", new VectorParams { Size=2, Distance=Distance.Cosine})" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
[ movie_collection ]
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "await client.ListCollectionsAsync()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Get collection info" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
{ "status": "Green", "optimizerStatus": { "ok": true }, "segmentsCount": "2", "config": { "params": { "shardNumber": 1, "vectorsConfig": { "params": { "size": "2", "distance": "Cosine" } }, "replicationFactor": 1, "writeConsistencyFactor": 1 }, "hnswConfig": { "m": "16", "efConstruct": "100", "fullS...
StatusGreen
OptimizerStatus
{ "ok": true }
Ok
True
Error
VectorsCount
0
SegmentsCount
2
Config
{ "params": { "shardNumber": 1, "vectorsConfig": { "params": { "size": "2", "distance": "Cosine" } }, "replicationFactor": 1, "writeConsistencyFactor": 1 }, "hnswConfig": { "m": "16", "efConstruct": "100", "fullScanThreshold": "10000", "maxIndexingThreads": "0", "onDisk": false }, "optimizerConfig":...
Params
{ "shardNumber": 1, "vectorsConfig": { "params": { "size": "2", "distance": "Cosine" } }, "replicationFactor": 1, "writeConsistencyFactor": 1 }
ShardNumber
1
OnDiskPayload
False
VectorsConfig
{ "params": { "size": "2", "distance": "Cosine" } }
Params
{ "size": "2", "distance": "Cosine" }
Size
2
DistanceCosine
HnswConfig
<null>
QuantizationConfig
<null>
OnDisk
False
HasOnDisk
False
ParamsMap
<null>
ConfigCaseParams
ReplicationFactor
1
HasReplicationFactor
True
WriteConsistencyFactor
1
HasWriteConsistencyFactor
True
ReadFanOutFactor
0
HasReadFanOutFactor
False
HnswConfig
{ "m": "16", "efConstruct": "100", "fullScanThreshold": "10000", "maxIndexingThreads": "0", "onDisk": false }
M
16
HasM
True
EfConstruct
100
HasEfConstruct
True
FullScanThreshold
10000
HasFullScanThreshold
True
MaxIndexingThreads
0
HasMaxIndexingThreads
True
OnDisk
False
HasOnDisk
True
PayloadM
0
HasPayloadM
False
OptimizerConfig
{ "deletedThreshold": 0.2, "vacuumMinVectorNumber": "1000", "defaultSegmentNumber": "0", "indexingThreshold": "20000", "flushIntervalSec": "5", "maxOptimizationThreads": "1" }
DeletedThreshold
0.2
HasDeletedThreshold
True
VacuumMinVectorNumber
1000
HasVacuumMinVectorNumber
True
DefaultSegmentNumber
0
HasDefaultSegmentNumber
True
MaxSegmentSize
0
HasMaxSegmentSize
False
MemmapThreshold
0
HasMemmapThreshold
False
IndexingThreshold
20000
HasIndexingThreshold
True
FlushIntervalSec
5
HasFlushIntervalSec
True
MaxOptimizationThreads
1
HasMaxOptimizationThreads
True
WalConfig
{ "walCapacityMb": "32", "walSegmentsAhead": "0" }
WalCapacityMb
32
HasWalCapacityMb
True
WalSegmentsAhead
0
HasWalSegmentsAhead
True
QuantizationConfig
<null>
PayloadSchema(empty)
PointsCount
0
IndexedVectorsCount
0
HasIndexedVectorsCount
True
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "await client.GetCollectionInfoAsync(\"movie_collection\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Add data to collection" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "var data = new[] \n", + "{\n", + " new PointStruct\n", + " {\n", + " Id = 1,\n", + " Vectors = new [] {0.10022575f, -0.23998135f},\n", + " Payload = \n", + " {\n", + " [\"title\"] = \"The Lion King\"\n", + " }\n", + " },\n", + " new PointStruct\n", + " {\n", + " Id = 2,\n", + " Vectors = new [] {0.10327095f, 0.2563685f},\n", + " Payload = \n", + " {\n", + " [\"title\"] = \"Inception\"\n", + " }\n", + " },\n", + " new PointStruct\n", + " {\n", + " Id = 3,\n", + " Vectors = new [] {0.095857024f, -0.201278f},\n", + " Payload = \n", + " {\n", + " [\"title\"] = \"Toy Story\"\n", + " }\n", + " },\n", + " new PointStruct\n", + " {\n", + " Id = 4,\n", + " Vectors = new [] {0.106827796f, 0.21676421f},\n", + " Payload = \n", + " {\n", + " [\"title\"] = \"Pulp Function\"\n", + " }\n", + " },\n", + " new PointStruct\n", + " {\n", + " Id = 5,\n", + " Vectors = new [] {0.09568083f, -0.21177962f},\n", + " Payload = \n", + " {\n", + " [\"title\"] = \"Shrek\"\n", + " }\n", + " }, \n", + "};" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [], + "source": [ + "await client.UpsertAsync(\"movie_collection\",data);" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Get count" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
5
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "await client.CountAsync(\"movie_collection\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Search collection\n", + "\n", + "Search for data using embedding vectors for the query \"A movie that's fun for the whole family\"." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": { + "dotnet_interactive": { + "language": "csharp" + }, + "polyglot_notebook": { + "kernelName": "csharp" + } + }, + "outputs": [ + { + "data": { + "text/html": [ + "
indexvalue
0
{ "id": { "num": "3" }, "payload": { "title": { "stringValue": "Toy Story" } }, "score": 0.66102695 }
Id
{ "num": "3" }
Num
3
HasNum
True
Uuid
HasUuid
False
PointIdOptionsCaseNum
Payload
keyvalue
title
{ "stringValue": "Toy Story" }
NullValueNullValue
HasNullValue
False
DoubleValue
0
HasDoubleValue
False
IntegerValue
0
HasIntegerValue
False
StringValue
Toy Story
HasStringValue
True
BoolValue
False
HasBoolValue
False
StructValue
<null>
ListValue
<null>
KindCaseStringValue
Score
0.66102695
Version
0
Vectors
<null>
1
{ "id": { "num": "5" }, "payload": { "title": { "stringValue": "Shrek" } }, "score": 0.6457999 }
Id
{ "num": "5" }
Num
5
HasNum
True
Uuid
HasUuid
False
PointIdOptionsCaseNum
Payload
keyvalue
title
{ "stringValue": "Shrek" }
NullValueNullValue
HasNullValue
False
DoubleValue
0
HasDoubleValue
False
IntegerValue
0
HasIntegerValue
False
StringValue
Shrek
HasStringValue
True
BoolValue
False
HasBoolValue
False
StructValue
<null>
ListValue
<null>
KindCaseStringValue
Score
0.6457999
Version
0
Vectors
<null>
2
{ "id": { "num": "1" }, "payload": { "title": { "stringValue": "The Lion King" } }, "score": 0.62360466 }
Id
{ "num": "1" }
Num
1
HasNum
True
Uuid
HasUuid
False
PointIdOptionsCaseNum
Payload
keyvalue
title
{ "stringValue": "The Lion King" }
NullValueNullValue
HasNullValue
False
DoubleValue
0
HasDoubleValue
False
IntegerValue
0
HasIntegerValue
False
StringValue
The Lion King
HasStringValue
True
BoolValue
False
HasBoolValue
False
StructValue
<null>
ListValue
<null>
KindCaseStringValue
Score
0.62360466
Version
0
Vectors
<null>
" + ] + }, + "metadata": {}, + "output_type": "display_data" + } + ], + "source": [ + "await client.SearchAsync(\"movie_collection\",new [] {0.12217915f, -0.034832448f }, limit:3)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": ".NET (C#)", + "language": "C#", + "name": ".net-csharp" + }, + "language_info": { + "name": "polyglot-notebook" + }, + "polyglot_notebook": { + "kernelInfo": { + "defaultKernelName": "csharp", + "items": [ + { + "aliases": [], + "languageName": "csharp", + "name": "csharp" + } + ] + } + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}