MCPcopy Index your code
hub / github.com/couchbase/couchbase-python-client / main

Function main

examples/acouchbase/vector_search_async.py:137–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

135
136
137async def main():
138 auth = PasswordAuthenticator('Administrator', 'password')
139 opts = ClusterOptions(auth)
140 cluster = await AsyncCluster.connect('couchbase://localhost', opts)
141 bucket = cluster.bucket('default')
142 await bucket.on_connect()
143 collection = bucket.default_collection()
144
145 # NOTE: validate paths (see note on line 18) if going to use setup/teardown functionality
146 keys = await setup(cluster, collection)
147 vector = load_test_vector()
148
149 search_req = search.SearchRequest.create(search.MatchAllQuery()).with_vector_search(
150 VectorSearch.from_vector_query(VectorQuery('vector_field', vector)))
151 search_iter = cluster.search(TEST_INDEX_NAME, search_req, SearchOptions(limit=2))
152 async for row in search_iter.rows():
153 print(f'row: {row}')
154
155 print(f'Metatdata: {search_iter.metadata()}')
156
157 # NOTE: only use in conjunction w/ setup() method
158 await teardown(cluster, collection, keys)
159
160
161if __name__ == '__main__':

Callers 1

Calls 15

ClusterOptionsClass · 0.90
VectorQueryClass · 0.90
SearchOptionsClass · 0.90
with_vector_searchMethod · 0.80
from_vector_queryMethod · 0.80
setupFunction · 0.70
load_test_vectorFunction · 0.70
teardownFunction · 0.70
connectMethod · 0.45
bucketMethod · 0.45
on_connectMethod · 0.45

Tested by

no test coverage detected