@@ -31,21 +31,22 @@ public QdrantCollection(string id, QdrantHttpClientWrapper vectorHttp, ILogger l
3131 this . _log = log ?? NullLogger . Instance ;
3232 }
3333
34+
3435 public async Task < DataEntry < VectorRecordData < float > > ? > GetVectorAsync ( string id )
3536 {
3637 var point = await this . FindQdrantPointByExternalIdAsync ( id ) ;
3738 if ( point == null ) { return null ; }
3839
3940 var result = new DataEntry < VectorRecordData < float > > ( key : point . ExternalId ,
40- value : new VectorRecordData < float > (
41- new Embedding < float > ( point . Vector ) ,
42- point . ExternalPayload ,
43- point . ExternalTags ) ) ;
41+ value : new VectorRecordData < float > (
42+ new Embedding < float > ( point . Vector ) ,
43+ point . ExternalPayload ,
44+ point . ExternalTags ) ) ;
4445
4546 return result ;
4647 }
4748
48- public async Task < IAsyncEnumerable < DataEntry < VectorRecordData < float > > > > GetAllVectorsAsync ( )
49+ public async IAsyncEnumerable < DataEntry < VectorRecordData < float > > > GetAllVectorsAsync ( )
4950 {
5051 HttpRequestMessage vectorRequest = FetchVectorsRequest
5152 . Fetch ( this . Name )
@@ -54,7 +55,19 @@ public async Task<IAsyncEnumerable<DataEntry<VectorRecordData<float>>>> GetAllVe
5455 var ( response , responseContent ) = await this . _vectorHttp . ExecuteHttpRequestAsync ( vectorRequest ) ;
5556 response . EnsureSuccessStatusCode ( ) ;
5657
57- return null ;
58+ var data = new FetchVectorsResponse ( responseContent ) ;
59+ Verify . Equals ( "ok" , data . Status , $ "Something went wrong while getting vectors for { this . Name } ") ;
60+
61+ foreach ( var point in data . VectorPointCollection )
62+ {
63+ var record = new DataEntry < VectorRecordData < float > > ( key : point . VectorId ! ,
64+ value : new VectorRecordData < float > (
65+ new Embedding < float > ( point . Vector ! ) ,
66+ point . Payload ! ,
67+ new List < string > ( ) ) ) ;
68+
69+ yield return record ;
70+ }
5871 }
5972
6073 public Task UpsertVectorAsync ( DataEntry < VectorRecordData < float > > record )
@@ -74,14 +87,13 @@ public async Task DeleteVectorAsync(string id)
7487 await this . DeleteVectorInternalAsync ( qdrantId ) ;
7588 }
7689
77- public async IAsyncEnumerable < KeyValuePair < DataEntry < VectorRecordData < float > > , double > > FindClosestAsync ( float [ ] target , int top = 1 ,
78- string [ ] ? requiredTags = null )
90+ public async IAsyncEnumerable < KeyValuePair < DataEntry < VectorRecordData < float > > , double > > FindClosestAsync ( float [ ] target , int top = 1 , string [ ] ? requiredTags = null )
7991 {
8092 this . _log . Debug ( "Searching top {0} closest vectors in {1}" , top ) ;
8193
8294 Verify . NotNull ( target , "The given vector is NULL" ) ;
8395
84- HttpRequestMessage request = SearchVectorsRequest
96+ using HttpRequestMessage request = SearchVectorsRequest
8597 . Create ( this . Name )
8698 . SimilarTo ( target )
8799 . HavingTags ( requiredTags )
@@ -107,10 +119,10 @@ public async IAsyncEnumerable<KeyValuePair<DataEntry<VectorRecordData<float>>, d
107119 foreach ( var v in data . Vectors )
108120 {
109121 var record = new DataEntry < VectorRecordData < float > > ( key : v . ExternalId ,
110- value : new VectorRecordData < float > (
111- new Embedding < float > ( v . Vector ) ,
112- v . ExternalPayload ,
113- v . ExternalTags ) ) ;
122+ value : new VectorRecordData < float > (
123+ new Embedding < float > ( v . Vector ) ,
124+ v . ExternalPayload ,
125+ v . ExternalTags ) ) ;
114126
115127 result . Add ( new KeyValuePair < DataEntry < VectorRecordData < float > > , double > ( record , v . Score ?? 0 ) ) ;
116128 }
@@ -125,8 +137,7 @@ public async IAsyncEnumerable<KeyValuePair<DataEntry<VectorRecordData<float>>, d
125137
126138 #region private ================================================================================
127139
128- private static List < KeyValuePair < DataEntry < VectorRecordData < float > > , double > > SortSearchResultByScore (
129- List < KeyValuePair < DataEntry < VectorRecordData < float > > , double > > list )
140+ private static List < KeyValuePair < DataEntry < VectorRecordData < float > > , double > > SortSearchResultByScore ( List < KeyValuePair < DataEntry < VectorRecordData < float > > , double > > list )
130141 {
131142 return ( from entry in list orderby entry . Value descending select entry ) . ToList ( ) ;
132143 }
@@ -141,7 +152,7 @@ private static List<KeyValuePair<DataEntry<VectorRecordData<float>>, double>> So
141152 {
142153 this . _log . Debug ( "Searching vector by external ID {0}" , externalId ) ;
143154
144- HttpRequestMessage request = SearchVectorsRequest
155+ using HttpRequestMessage request = SearchVectorsRequest
145156 . Create ( this . Name , this . VectorSize )
146157 . HavingExternalId ( externalId )
147158 . IncludePayLoad ( )
@@ -189,7 +200,7 @@ private async Task UpsertVectorInternalAsync(DataEntry<VectorRecordData<float>>
189200 if ( response . StatusCode == HttpStatusCode . UnprocessableEntity
190201 && responseContent . Contains ( "data did not match any variant of untagged enum ExtendedPointId" ) )
191202 {
192- throw new Exception ( "The vector ID must be a GUID string" ) ;
203+ throw new VectorDbException ( "The vector ID must be a GUID string" ) ;
193204 }
194205
195206 try
@@ -217,5 +228,7 @@ private async Task DeleteVectorInternalAsync(string qdrantPointId)
217228 await this . _vectorHttp . ExecuteHttpRequestAsync ( request ) ;
218229 }
219230
231+
232+
220233 #endregion
221234}
0 commit comments