I have code that runs both FTS (Full-Text Search) and vector search together. Upon checking the results, it seems that vector search is not performed within the filtered values from FTS, but rather, the filtering and vector search are done separately, and then the results are combined. How can I resolve this issue? Below 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
import random
from couchbase.n1ql import N1QLQuery
client=OpenAI(api_key='api')
cluster = Cluster(
"couchbase://ip",
authenticator=PasswordAuthenticator(
"id","pw"
)
)
question="something"
bucket = cluster.bucket("my_bucket")
scope = bucket.scope("my_scope")
authorities = random.sample(range(1, 3001), 100)
authorities = [str(auth) for auth in authorities]
permissions_query = ' or '.join([f'authority:"{auth}"' for auth in authorities])
search_index = "my-index"
try:
vector = client.embeddings.create(input = [question], model="text-embedding-3-small").data[0].embedding
search_req = search.SearchRequest.create(search.MatchQuery(permissions_query)).with_vector_search(
VectorSearch.from_vector_query(VectorQuery('title_body_vector', vector, num_candidates=100)))
# 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=10,fields=["title","body"]))
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()