@@ -39,16 +39,30 @@ with arcadedb.create_database("./vector_demo") as db:
3939 to_java_float_array(embedding),
4040 )
4141
42- results = index.find_nearest([0.9 , 0.1 , 0.0 ], k = 2 )
43- for vertex, score in results:
44- print (vertex.get(" text" ), score)
42+ rows = db.query(
43+ " sql" ,
44+ " SELECT vectorNeighbors('Doc[embedding]', [0.9, 0.1, 0.0], 2) as res" ,
45+ ).to_list()
46+ for hit in rows[0 ].get(" res" , []):
47+ record = hit.get(" record" )
48+ if record is not None :
49+ print (record.get(" text" ), hit.get(" distance" ))
4550```
4651
4752## API Essentials
4853
54+ Preferred split:
55+
56+ - Use Python object API for vector index creation and configuration.
57+ - Prefer SQL or Cypher for vector retrieval/search, because search composes naturally
58+ with filters, projections, and graph traversal.
59+ - Treat ` find_nearest() ` and ` find_nearest_by_key() ` as convenience wrappers for
60+ simple embedded-mode workflows.
61+
4962- Vector property type must be ` ARRAY_OF_FLOATS ` .
5063- `create_vector_index(vertex_type, vector_property, dimensions,
51- distance_function="cosine", max_connections=16, beam_width=100, quantization="INT8",
64+ id_property=None, distance_function="cosine", max_connections=16,
65+ beam_width=100, quantization="INT8",
5266 location_cache_size=None, graph_build_cache_size=None, mutations_before_rebuild=None,
5367 store_vectors_in_graph=False, add_hierarchy=True, pq_subspaces=None, pq_clusters=None,
5468 pq_center_globally=None, pq_training_limit=None, build_graph_now=True)`
@@ -60,6 +74,11 @@ with arcadedb.create_database("./vector_demo") as db:
6074 - ` ef_search ` optionally overrides the exact-search beam width.
6175 - Leave it as ` None ` to use ArcadeDB's default/adaptive behavior.
6276 - ` allowed_rids ` filters candidates server-side (useful for metadata-prefilter).
77+ - ` find_nearest_by_key(key, k=10, ef_search=None, allowed_rids=None) `
78+ - Looks up the source vector by the index ` id_property ` and then runs the same
79+ Python search path as ` find_nearest() ` .
80+ - ` get_metadata() ` returns stable index metadata such as dimensions, similarity
81+ function, configured ` id_property ` , quantization, and cache/build settings.
6382
6483## Distance Functions (scoring behavior)
6584
@@ -161,6 +180,93 @@ rids = [row.get_rid() for row in db.query("sql", "SELECT @rid FROM Doc WHERE top
161180results = index.find_nearest(query_vec, k = 5 , allowed_rids = rids)
162181```
163182
183+ ## Preferred Search Surface: SQL / Cypher
184+
185+ For new code, prefer query APIs for search.
186+
187+ ### SQL filtered vector search with score shaping
188+
189+ ``` python
190+ qvec_literal = " [" + " , " .join(str (float (x)) for x in query_vec) + " ]"
191+
192+ rows = db.query(
193+ " sql" ,
194+ (
195+ " SELECT title, category, distance, (1 - distance) AS score "
196+ " FROM (SELECT expand(`vector.neighbors`('Article[embedding]', "
197+ f " { qvec_literal} , 50))) WHERE category = ? ORDER BY distance LIMIT 5 "
198+ ),
199+ " category_42" ,
200+ ).to_list()
201+ ```
202+
203+ ### SQL self-exclusion
204+
205+ ``` python
206+ rows = db.query(
207+ " sql" ,
208+ (
209+ " SELECT title, distance, (1 - distance) AS score "
210+ " FROM (SELECT expand(`vector.neighbors`('Movie[embedding]', "
211+ f " { qvec_literal} , 20))) WHERE title <> ? ORDER BY distance LIMIT 10 "
212+ ),
213+ movie_title,
214+ ).to_list()
215+ ```
216+
217+ ### Cypher search with score shaping
218+
219+ ``` python
220+ rows = db.query(
221+ " opencypher" ,
222+ (
223+ " CALL vector.neighbors('Doc[embedding]', $vec, $k) "
224+ " YIELD name, distance RETURN name, (1 - distance) AS score ORDER BY score DESC"
225+ ),
226+ {" vec" : query_vec, " k" : 5 },
227+ ).to_list()
228+ ```
229+
230+ ## Search from an Existing Record
231+
232+ ``` python
233+ with arcadedb.create_database(" ./vector_demo" ) as db:
234+ db.command(" sql" , " CREATE VERTEX TYPE Doc" )
235+ db.command(" sql" , " CREATE PROPERTY Doc.slug STRING" )
236+ db.command(" sql" , " CREATE PROPERTY Doc.embedding ARRAY_OF_FLOATS" )
237+
238+ index = db.create_vector_index(
239+ vertex_type = " Doc" ,
240+ vector_property = " embedding" ,
241+ dimensions = 3 ,
242+ id_property = " slug" ,
243+ )
244+
245+ with db.transaction():
246+ db.command(
247+ " sql" ,
248+ " INSERT INTO Doc SET slug = ?, embedding = ?" ,
249+ " doc-a" ,
250+ to_java_float_array([1.0 , 0.0 , 0.0 ]),
251+ )
252+ db.command(
253+ " sql" ,
254+ " INSERT INTO Doc SET slug = ?, embedding = ?" ,
255+ " doc-b" ,
256+ to_java_float_array([0.9 , 0.1 , 0.0 ]),
257+ )
258+
259+ neighbors = index.find_nearest_by_key(" doc-a" , k = 2 )
260+ metadata = index.get_metadata()
261+
262+ print (metadata[" dimensions" ], metadata[" id_property" ])
263+ for record, distance in neighbors:
264+ print (record.get(" slug" ), distance)
265+ ```
266+
267+ Use this helper when you want a small embedded-mode shortcut. For richer filtering,
268+ projection, self-exclusion, or score shaping, prefer SQL/Cypher queries.
269+
164270## Quantization
165271
166272- ` quantization ` accepts ` "INT8" ` , ` "BINARY" ` , ` "PRODUCT" ` (PQ), or ` None ` (full precision).
0 commit comments