Vector Search on Scoped Index Returns 0 Results Despite Correct Setup (Python SDK)

Hello,

I’m facing a persistent issue where a vector search query consistently returns 0 documents, even though the setup appears to be correct in every aspect. I have exhausted all application-level debugging and believe this might be a bug or a specific behavior of the Search Service.

Environment:

  • Couchbase Server Version: [Coloque aqui a sua versão exata, ex: 7.2.4 Community Edition]
  • Operating System: Rocky Linux 9.6 (Kernel 5.14.0)
  • Python SDK Version: couchbase==4.4.0
  • Execution: Running a Python/Flask application inside a Docker container.

What is Working:

  1. The application connects successfully to the Couchbase cluster using host.docker.internal.
  2. At startup, the application successfully runs a DELETE FROM ... query to clear the collection.
  3. It then successfully upserts 18 documents, each with a 384-dimension embedding vector.
  4. The application uses the management API (cluster.search_indexes().get_indexed_documents_count()) to wait until it confirms the Search Index (xu_passeios.dados.passeios_v2_idx) has processed all 18 documents. This check succeeds every time.
  5. The search call (scope.search with a VectorSearch payload) executes without any Python exceptions.

The Problem: Despite all of the above, the result from the scope.search call always indicates 0 total hits (total_rows: 0), for both generic and highly specific queries (e.g., searching for “Noronha” when documents explicitly contain this term).

Vector search community edition? - Couchbase Server - Couchbase Forums Vector search community edition? - Couchbase Server - Couchbase Forums

I’m using Couchbase Server Enterprise Edition 7.6.6 build 6126.

@idxBasic Could you please share the index definition & a sample document? Also, the code snippet that you are trying?

Hi @nithishr,

Thank you so much for looking into this. I really appreciate the help. After a long debugging session, we have managed to solve all environment, configuration, and application startup issues, but the vector search still returns 0 documents.

As requested, here is the index definition, a sample document, and the Python code snippet we are trying.

1. Index Definition (passeios_v2_idx)

This is the JSON definition used to create a new index from scratch on a completely new and empty bucket/scope/collection.

JSON{ "name": "passeios_v2_idx", "type": "fulltext-index", "params": { "doc_config": { "docid_prefix_delim": "", "docid_regexp": "", "mode": "scope.collection.type_field", "type_field": "type" }, "mapping": { "default_analyzer": "standard", "default_datetime_parser": "dateTimeOptional", "default_field": "_all", "default_mapping": { "dynamic": false, "enabled": false }, "default_type": "_default", "docvalues_dynamic": false, "index_dynamic": true, "store_dynamic": true, "type_field": "_type", "types": { "dados.conteudo": { "dynamic": false, "enabled": true, "properties": { "embedding": { "enabled": true, "dynamic": false, "fields": [ { "dims": 384, "index": true, "name": "embedding", "similarity": "cosine", "type": "vector" } ] }, "text": { "enabled": true, "dynamic": false, "fields": [ { "analyzer": "standard", "index": true, "name": "text", "store": true, "type": "text" } ] } } } } }, "store": { "indexType": "scorch" } } }

2. Sample Document

This is an example of one of the 18 documents that are being successfully inserted into the xu_passeios.dados.conteudo collection. The embedding field contains a valid list of 384 float values generated by the all-MiniLM-L6-v2 model.

JSON{ "id": "doc_4", "text": "Fernando de Noronha - Pacote Completo 7 dias: Inclui voos de Recife, hospedagem na Pousada Maravilha, mergulho com cilindro, trilha do Atalaia, passeio de barco para ver golfinhos, jantar no Mergulhão. Preço: R$ 8.500 por pessoa (alta temporada) / R$ 6.200 (baixa temporada).", "embedding": [ -0.08839886, 0.09436358, -0.0045749, "... 381 more float values ..." ], "metadata": { "categoria": "ofertas", "tags": [ "fernando", "preços", "mergulho", "hospedagem" ] }, "type": "dados.conteudo" }

3. Python Code Snippet (The Search Function)

This is the final version of the search function from my CouchbaseVectorStore class. It uses the exact syntax recommended in the official Couchbase documentation that I found.

Note: Config.INDEX_NAME correctly resolves to 'passeios_v2_idx'.

`Pythonfrom config import Config
from couchbase.exceptions import CouchbaseException
from couchbase.options import SearchOptions
import couchbase.search as search
from couchbase.search import SearchScanConsistency
from couchbase.vector_search import VectorSearch, VectorQuery

def search_documents(self, query_text: str, limit: int = 4) → list:
“”“Performs a vector search using the officially documented syntax.”“”
try:
# This function correctly generates a 384-dimension vector
query_embedding = self._generate_embedding(query_text)
if not query_embedding:
return

    search_index_name = Config.INDEX_NAME

    # Using the exact syntax from the documentation
    vector_query = VectorQuery("embedding", query_embedding, num_candidates=limit + 10)
    vector_search = VectorSearch.from_vector_query(vector_query)
    search_request = search.SearchRequest.create(search.MatchNoneQuery()).with_vector_search(vector_search)
    
    result = self.scope.search(
        index=search_index_name,
        request=search_request,
        options=SearchOptions(
            limit=limit,
            fields=["text"],
            scan_consistency=SearchScanConsistency.REQUEST_PLUS
        )
    )

    documents = [row.fields for row in result.rows() if row.fields]
    logger.info(f"✅ Vector search performed for '{query_text}'. Found {len(documents)} documents.")
    return documents
    
except Exception as e:
    logger.error(f"❌ An unexpected error occurred during search: {e}", exc_info=True)
    return []

`

Summary of the problem: My application startup logic now correctly waits for the index to report all 18 documents as processed. The application then runs the search_documents function with a specific query like “Noronha”. The function executes without any Python exceptions, but the result from Couchbase consistently reports 0 documents found.

Any insight you have would be greatly appreciated. Thank y

Normally, you don’t get the results from the Vector Search if the index definition is not quite right (vector dimensions, fields, storing the values in the index, etc). In this case, the index looks alright.
The SDK code also looks fine.

Have you tried running the same code without the scoped index, i.e., Cluster.search() instead of Scope.search()? I have a suspicion that your index is at the Cluster level rather than the Scoped one. In my scoped index defintion JSON (on 7.6.6-6126), the name of the index is shown with the bucket.scope.index_name rather than the index_name.