“I want to filter and search the permission section in Couchbase.”
“I want to search for content that only contains the values in this list: ex,[1,2,3,4,5].”
Here is my code
from couchbase.cluster import Cluster
from couchbase.options import ClusterOptions
from couchbase.auth import PasswordAuthenticator
from couchbase.exceptions import CouchbaseException
import couchbase.search as search
from couchbase.options import SearchOptions
from couchbase.vector_search import VectorQuery, VectorSearch
import csv
import json
from openai import OpenAI
client=OpenAI(api_key='api_key')
cluster = Cluster(
"couchbase://my_address",
authenticator=PasswordAuthenticator(
"ID","PW"
)
)
question="question"
bucket = cluster.bucket("my_bucket")
scope = bucket.scope("my_scope")
search_index = "search-index"
try:
vector = client.embeddings.create(input = [question], model="text-embedding-3-small").data[0].embedding
search_req = search.SearchRequest.create(search.MatchQuery("['1','2','3']")).with_vector_search(
VectorSearch.from_vector_query(VectorQuery('title_body_vector', vector, num_candidates=5)))
# Change the limit value to return more results. Change the fields array to return different fields from your Search index.
result = scope.search(search_index, search_req, SearchOptions(limit=13,fields=["authority"]))
for row in result.rows():
print("Found row: {}".format(row))
print("Reported total rows: {}".format(
result.metadata().metrics().total_rows()))
except CouchbaseException as ex:
import traceback
traceback.print_exc()