Home / GenAI Engineer practice test / Data Preparation

Free · 8 questions with explanations

Data Preparation: Databricks Generative AI Engineer Associate Practice Questions

Exam-style questions on Data Preparation. Pick your answer, then open the explanation to see why it's right — and why the other options are wrong.

Updated November 11, 2026

1 Data Preparation

A generative AI engineer is building a product FAQ chatbot. The source data is a structured FAQ document with 350 question-answer pairs, each written as a line starting with Q: followed by the question text and a line starting with A: followed by the answer text. Each QA pair is 2–8 sentences on average. Users will query the chatbot with questions semantically similar to the FAQ questions. The engineer is choosing between several chunking strategies. Which approach produces the BEST retrieval quality for this specific document structure?

  1. ARecursive character splitting into 512-token chunks with a 50-token overlap and the default whitespace separators
  2. BOne chunk per QA pair, so that each FAQ question is embedded and retrieved together with its complete answer
  3. CSeparate chunks for each question and each answer, so that either embedding can match the user's query
  4. DFixed-size 128-token chunks with no overlap, since short FAQ answers fit and smaller chunks give finer-grained index entries
  5. ESentence-level chunks across the whole document, with a chunk boundary at each sentence end regardless of QA structure
Show answer & explanation

Correct answer: B

WHY B is correct: When source documents have a natural semantic unit — in this case, the Q+A pair — the chunking strategy should preserve that unit. A document with explicit Q/A structure provides a strong signal: each QA pair is a self-contained knowledge nugget. When a user asks a question similar to a FAQ question, embedding-based retrieval will score the chunk highest when the chunk contains the FAQ question + answer as a complete unit, because the FAQ question and the user query will be semantically close, and the complete answer is co-located. Splitting per-QA-pair is sometimes called 'structure-aware' or 'document-aware' chunking. WHY NOT A: Recursive character splitting ignores the QA structure and may split a QA pair mid-answer or merge partial answers from two adjacent QA pairs into one chunk. A generic strategy that ignores document structure always underperforms a structure-aware strategy when clear semantic units exist. WHY NOT C: Separating the question from its answer into different chunks breaks the retrieval-answer co-location property. If a user query retrieves the FAQ question chunk (high similarity, since both are questions), the retrieved chunk contains no answer text — the LLM must then try to answer without any retrieved context. If the answer chunk is retrieved (lower similarity, since answer text is often declarative while queries are interrogative), it lacks the question's framing. WHY NOT D: Fixed 128-token chunks cut some QA pairs mid-answer (an 8-sentence answer may exceed 128 tokens), again breaking the semantic unit. Small chunks also create more noise in the index by splitting structural units that should stay together. WHY NOT E: Sentence-level chunking across the entire document obliterates the QA structure. A retrieved single sentence like 'The return window is 30 days' has almost no context about what product, what conditions, or what exceptions apply. The user would receive ambiguous, context-free fragments instead of complete answers.

2 Data Preparation

A generative AI engineer is designing a high-quality RAG pipeline for a medical knowledge base. The current pipeline retrieves top-5 chunks using a bi-encoder with cosine similarity. The engineer wants to add a re-ranking stage using sentence_transformers.CrossEncoder. Which statement correctly describes a key LIMITATION of cross-encoder re-ranking that the engineer must account for when designing the system?

  1. ACross-encoders accept inputs of up to 128 tokens, so longer retrieved chunks must be truncated before re-ranking, which loses information
  2. BCross-encoders need the query and the chunk to be in the same language, so a multilingual corpus cannot be re-ranked
  3. CCross-encoders are offered as proprietary cloud re-ranking APIs, so using one means sending the medical text to an external service
  4. DCross-encoder re-ranking improves answer accuracy regardless of first-stage retrieval quality, so it can only maintain or raise precision
  5. ECross-encoders cannot pre-index embeddings, so each query-chunk pair is scored at query time, which limits them to a small candidate set
Show answer & explanation

Correct answer: E

WHY E is correct: This is the fundamental, well-documented limitation of cross-encoders. A cross-encoder scores a (query, document) pair by running a full transformer forward pass on both texts simultaneously. This requires one separate forward pass per candidate document. For a corpus of 1 million chunks: - **ANN (Approximate Nearest Neighbor) bi-encoder search**: ~5–50 milliseconds (pre-computed embeddings + vector index) - **Cross-encoder scoring 1M chunks**: 1M × ~5ms per pair = ~1,400 hours per query This makes cross-encoders completely impractical as a first-stage retriever over large indices. They are practical ONLY as second-stage re-rankers applied to a small set of candidates (20–100) pre-selected by the bi-encoder. This two-stage architecture is the canonical 'retrieve-then-rerank' pipeline, and the sentence_transformers documentation explicitly frames CrossEncoder usage this way. WHY NOT A: Cross-encoder context window limits depend on the underlying model, typically 512 tokens for BERT-based models or 4,096+ tokens for modern transformer architectures. The limit is not universally 128 tokens, and truncation behavior is configurable. The 128-token claim is false. WHY NOT B: Multilingual cross-encoder models exist (e.g., cross-encoder/mmarco-mMiniLMv2-L12-H384-v1 from the sentence_transformers library). The claim that cross-encoders require same-language query and document is false — it depends on the model trained. WHY NOT D: Cross-encoder re-ranking can only re-rank candidates within the set retrieved by the first-stage bi-encoder. If the relevant chunk was not in the top-K bi-encoder results (recall failure), the cross-encoder cannot elevate it because it never sees it. The cross-encoder is bounded by the recall ceiling of the first stage. Additionally, if the cross-encoder model is poorly calibrated or mismatched to the domain, re-ranking can decrease precision. WHY NOT C: Multiple open-source cross-encoder models are available from Hugging Face Model Hub via the sentence_transformers library (e.g., cross-encoder/ms-marco-MiniLM-L-6-v2, cross-encoder/ms-marco-TinyBERT-L-2-v2). These can run entirely on-premises without any cloud API call. The claim that only proprietary cloud APIs exist is false.

3 Data Preparation

A generative AI engineer is building a RAG application that ingests four types of source documents: (1) native digital PDFs with text layers (financial reports), (2) scanned image-based PDFs with no text layer (legacy paper contracts that were photocopied and scanned), (3) HTML web pages from an internal wiki, and (4) .docx Word documents. The engineer needs to extract the text content from all four types using Python. Which approach handles all four source types through a single API, with the least format-specific code?

  1. APyPDF2 for all four types, using its text extraction for both kinds of PDF and its document reader for HTML and DOCX files
  2. Bpdfminer.six for digital PDFs, pytesseract with Pillow for scanned PDFs, BeautifulSoup for HTML pages and python-docx for DOCX files
  3. CThe unstructured library for all four types, using its partition() function to detect the file type and apply OCR where needed
  4. Dscrapy for the wiki pages and any web-accessible PDF or DOCX files, and textract for the remaining binary documents such as the scanned contracts
  5. Epypdf for digital PDFs, pytesseract with pdf2image for scanned PDFs, BeautifulSoup for HTML pages and python-docx for DOCX files
Show answer & explanation

Correct answer: C

WHY C is correct: The unstructured library is built for multi-format extraction. Its partition() function detects whether a file is a PDF, DOCX, HTML page or image and routes it to the right internal parser, applying Tesseract OCR when a PDF has no extractable text layer. One consistent call handles all four source types. WHY NOT A: PyPDF2 (now pypdf) extracts text from digital PDFs that have an embedded text layer. It has no HTML parser, no DOCX parser and no OCR, so a scanned PDF returns empty strings. It has no general document reader for other formats. WHY NOT B: This combination can be made to work, but it needs a separate library and separate branching code for each format, which is the opposite of a single API. The unstructured library covers the same four formats with one call and automatic type detection. WHY NOT E: This combination works, with pdf2image rendering scanned pages for pytesseract, but it still means four libraries and format-specific code paths to maintain. A single partition() call in the unstructured library is the simpler and more maintainable choice. WHY NOT D: scrapy is a web crawling framework for fetching pages over HTTP; it does not parse PDF or DOCX binaries. textract wraps external system utilities that must be installed separately and does not OCR image-based PDFs without extra configuration.

4 Data Preparation

A generative AI engineer is designing a RAG system for a large collection of academic research papers. Each paper has an abstract, 4-8 sections with subsection headings, and a references section. User queries vary from 'What does the abstract of the Smith 2023 paper say about climate sensitivity?' to 'How do recent papers frame the debate between solar forcing and greenhouse gas causation?' The engineer wants to enable both precise abstract-level retrieval and broad conceptual cross-paper retrieval in a single system. Which retrieval system design BEST supports this?

  1. ASplit each paper into uniform fixed-size 512-token chunks with no section metadata, and rely on vector similarity alone to surface abstract text for abstract queries and body text for broad queries.
  2. BIndex the abstract of each paper as a single chunk and leave the body sections out of the index, then answer both abstract-specific queries and broad cross-paper queries from that abstract-level index.
  3. CDecompose each paper with an LLM into atomic, self-contained propositions and index each one as a separate chunk, then answer abstract queries and broad cross-paper queries from that proposition-level index built across the corpus.
  4. DStore each abstract as its own chunk and split body sections at paragraph boundaries, tagging chunks with section and paper metadata; filter on section for abstract queries and search the full index for broad ones.
  5. ESample random 200-token windows from each paper to spread coverage evenly across sections without structural bias, then answer abstract queries and broad cross-paper queries from that sampled index.
Show answer & explanation

Correct answer: D

WHY D: Metadata-enriched chunking with semantic boundaries combines two techniques that suit academic papers. Tagging each chunk with section: 'abstract', paper_id, year and authors enables metadata filtering at retrieval time: for 'What does the abstract of the Smith 2023 paper say?' the retriever can filter on section = 'abstract', authors containing 'Smith' and year = 2023 before the similarity search, which dramatically reduces the search space and improves precision. Splitting body sections at paragraph boundaries (semantic chunking) rather than arbitrary token positions preserves the coherent argument structure of academic paragraphs and improves embedding quality, and for broad conceptual queries ('debate between solar forcing and greenhouse gas causation') a full index search with no metadata filter retrieves the most relevant paragraphs from across all papers. This leverages document structure as retrieval filters. WHY NOT A: Uniform 512-token chunks with no section metadata throw away the one signal that tells an abstract from body text. A query about the Smith 2023 abstract then returns whichever chunks are most similar, from any section of any paper, and vector similarity alone cannot guarantee that the abstract comes back. WHY NOT C: Proposition-based chunking decomposes content into atomic factual claims and works well for dense factual retrieval. However, it requires running an LLM over every sentence of every paper (computationally expensive for a large academic corpus), offers no section filter for abstract queries, and propositions lose the relational context between claims within a paragraph that synthesis queries about debates and frameworks need. WHY NOT B: Indexing only abstracts discards 90%+ of each paper's informational content. The body sections contain methodology, experimental results and discussion of debates that are essential for synthesis questions; an abstract-only index cannot answer 'How do recent papers frame the debate between X and Y?' because that framing is in the discussion sections, not the abstract summaries. WHY NOT E: Random subsampling introduces arbitrary coverage gaps: critical sections may be underrepresented or absent from the sample, and there is no principled way to ensure that abstracts, conclusions or specific arguments are consistently represented. It is an anti-pattern that trades a solvable structural chunking problem for non-deterministic coverage quality.

5 Data Preparation

A generative AI engineer has built a retrieval system for a RAG application and wants to evaluate its performance. They have a golden evaluation dataset of 150 question/answer pairs, where each pair includes: the question, the ground-truth answer, and the list of source document chunk IDs that contain the information needed to answer the question. The retrieval system returns the top-5 chunk IDs for each query. Which pair of metrics is MOST appropriate to evaluate retrieval quality using this evaluation dataset?

  1. ABLEU and ROUGE-L, which score the n-gram and longest-common-subsequence overlap between retrieved chunk text and the ground-truth answer
  2. BPerplexity and cross-entropy loss of the retrieved chunks, where lower values indicate more fluent text the LLM can use more effectively
  3. CRecall@K and Precision@K, computed by comparing the top-5 retrieved chunk IDs with the ground-truth chunk IDs
  4. DQuery latency in milliseconds and index storage size, since a retriever that is too slow or too large is not viable in production
  5. EAnswer correctness and faithfulness from an LLM judge, since the quality of the final generated answer reflects how well retrieval worked
Show answer & explanation

Correct answer: C

WHY C is correct: The question specifically asks to evaluate *retrieval* performance using a dataset that includes ground-truth chunk IDs. Recall@K, Precision@K, and Mean Reciprocal Rank (MRR) are purpose-built information retrieval metrics that measure whether the retriever returns the correct chunks: - **Recall@K**: what fraction of the relevant chunks appear in the top K retrieved? (Catches whether the retriever finds all needed information) - **Precision@K**: what fraction of the K retrieved chunks are actually relevant? (Measures retrieval noise) - **MRR**: where does the first relevant chunk appear in the ranked list? (Measures ranking quality) With ground-truth chunk IDs available, these metrics can be computed directly and faithfully. WHY NOT A: BLEU and ROUGE-L measure lexical overlap between output text strings — they are generation quality metrics used to evaluate summarization and translation outputs. They cannot be directly applied to compare chunk IDs or rank positions, and they measure surface text similarity rather than retrieval recall/precision. WHY NOT B: Perplexity measures a language model's uncertainty in predicting a text sequence — it is a training metric for language models, not a retrieval quality metric. Low perplexity means text is predictable/fluent, not that the chunk is relevant to the user's question. A fluent but irrelevant chunk would have low perplexity and incorrectly score as a high-quality retrieval. WHY NOT D: Latency and storage are operational/infrastructure metrics, not retrieval quality metrics. A fast retriever that returns wrong chunks scores perfectly on latency but fails completely on the task. These metrics are important in production profiling but do not measure retrieval effectiveness. WHY NOT E: Answer correctness and faithfulness (LLM-as-judge end-to-end metrics) evaluate the full RAG pipeline including the generation step. While ultimately important, they conflate retrieval quality with generation quality — a poor-quality retriever can sometimes be masked by a powerful enough LLM. To specifically diagnose retrieval problems, isolated retrieval metrics (Recall@K, Precision@K) are needed.

6 Data Preparation

A generative AI engineer is building a technical documentation chatbot for a software product. The documentation corpus includes 1,200 Markdown files. After building the initial RAG pipeline, retrieval quality evaluations show poor results for questions about API endpoints. Investigation reveals that retrieved chunks frequently contain only code block content without any surrounding explanatory text, and these code-only chunks push out substantive explanation chunks from the top-k results. Additionally, some retrieved chunks contain only a list of hyperlinks (the Markdown 'See also' sections). Which TWO pre-processing filters most directly address these quality degradation sources?

  1. ARemove code blocks from the documents before chunking and index the prose explanation text on its own
  2. BDrop chunks that are more than 70% code tokens and contain fewer than 30 words of natural-language text
  3. CStrip See also and References sections with a regex that matches consecutive lines made up of Markdown links
  4. DConvert the Markdown files to plain text by stripping formatting symbols such as #, ** and - before chunking
  5. ERaise the number of retrieved chunks from top-3 to top-10 so an explanation chunk is more likely to be included
Show answer & explanation

Correct answer: BC

WHY B is correct: This filter targets the first identified problem directly. A chunk that is almost all code produces an embedding dominated by identifiers and syntax rather than the meaning a user asks about, yet it still takes a top-k slot from a prose explanation. Requiring a minimum amount of natural-language text removes those low-value chunks while code that sits beside explanatory text stays in the index. WHY C is correct: This filter targets the second identified problem directly. A See also section made of hyperlinks is a navigation aid: the link text and URL paths carry no answerable knowledge and only add noise to retrieval, so these sections should be stripped before chunking. WHY NOT A: Removing code blocks altogether is too aggressive. Technical answers often depend on a code example shown next to its explanation. The problem is chunks that are code with no prose around them, not code appearing inside chunks that also explain it. WHY NOT D: Stripping Markdown symbols is a reasonable cleaning step, but it does not address either problem. A code-only chunk is still code-only after the heading and emphasis symbols are gone, and a link section is still a list of link text and URLs. WHY NOT E: Raising top-k is a mitigation rather than a fix. It uses more of the context window, adds latency and brings in more irrelevant content, which makes generation harder. The low-quality index entries are the root cause and must be handled during data preparation.

7 Data Preparation

A generative AI engineer is building a RAG system for a 500-page technical specification document. Users ask two types of questions: (1) detail-oriented lookup questions like 'What is the maximum packet size defined in Section 3.4.2?' — requiring a small, precise chunk, and (2) broad synthesis questions like 'How does the error handling strategy in the network layer relate to the application layer?' — requiring large sections of multi-section context. With a standard fixed-size 256-token chunking strategy, detail queries work well but synthesis queries fail because each chunk only captures a small portion of a large multi-section topic. Which advanced chunking strategy BEST addresses the dual query type requirement?

  1. AIncrease the chunk size to 4,096 tokens across the document so synthesis queries get more context and the LLM extracts details from the larger chunks
  2. BReplace dense vector retrieval with BM25 keyword retrieval, which matches exact technical terms for detail queries and topic terms for synthesis
  3. CUse sentence window retrieval: index individual sentences and, when one is retrieved, return it with the N sentences before and after it
  4. DUse parent-child chunking: embed and retrieve small child chunks of about 128 tokens, but pass each one's larger parent section to the LLM
  5. EStore the document as a single chunk and rely on the LLM's 128K-token context window to handle both detail and synthesis queries
Show answer & explanation

Correct answer: D

WHY D is correct: Parent-child (also called 'small-to-big' or 'hierarchical') chunking is the advanced strategy specifically designed to serve dual granularity requirements. The architecture is: 1. **Indexing**: Chunk the document into small child chunks (128 tokens) AND large parent chunks (full sections, ~1,024 tokens). Index ONLY the small child chunk embeddings in the vector store. 2. **Retrieval**: Execute embedding similarity search on small child chunk embeddings — this gives high retrieval precision because small chunks have tightly-scoped embedding vectors. 3. **Context expansion**: Once the relevant child chunk is identified, retrieve its mapped parent chunk and pass the parent (large) chunk to the LLM. For detail queries: the small child chunk for Section 3.4.2 is retrieved precisely, and the parent section provides the full specification context. For synthesis queries: retrieving child chunks from multiple sections causes each query to return multiple parents, effectively loading multiple full sections into the LLM's context for cross-section synthesis. WHY NOT A: Uniform 4,096-token chunks improve synthesis queries but hurt detail queries. The large chunk's embedding vector averages signals from thousands of tokens, making it less precise for specific detail retrieval. A chunk covering 4,096 tokens of a complex spec will score lower similarity to a specific technical detail query than a 128-token chunk containing that exact detail. WHY NOT C: Sentence Window Retrieval expands context within a local N-sentence neighborhood. This works well for questions requiring a few surrounding sentences. However, for synthesis questions requiring content from two different sections (network layer + application layer), the N-sentence window around a network layer sentence would not capture the application layer section — the sections may be hundreds of tokens apart. WHY NOT E: Embedding the entire 500-page document as one chunk makes retrieval meaningless — all queries return the same single chunk, regardless of relevance. LLM long context windows (128K tokens) typically represent ~100 pages, not 500 pages, and processing a full spec on every query is extremely costly in latency and API tokens. This eliminates the purpose of chunking entirely. WHY NOT B: BM25 keyword retrieval is a complement to dense retrieval (useful in hybrid search), not a universal solution to dual granularity. For synthesis queries about cross-section relationships, keyword retrieval may return sections with overlapping technical terms but miss semantically related sections that use different vocabulary. Dense retrieval's semantic understanding is superior for synthesis-type questions.

8 Data Preparation

A generative AI engineer has completed text extraction and chunking of 5,000 PDF documents. Each chunk is represented as a Python dictionary: {'doc_id': str, 'chunk_index': int, 'chunk_text': str, 'source_filename': str, 'page_number': int}. The engineer needs to write all chunks to a managed Delta Lake table in Unity Catalog (catalog.schema.chunks_bronze) for use as the input to a vector embedding pipeline. Which sequence of operations is CORRECT?

  1. ABuild a DataFrame with spark.createDataFrame(chunk_list) and an explicit StructType schema, then write it with format('delta') and saveAsTable('catalog.schema.chunks_bronze')
  2. BReturn the chunks from a pandas UDF applied to an empty DataFrame and write the result with saveAsTable, as required for non-Spark Python data
  3. CSerialize the dicts to a JSON file, upload it to DBFS, load it with spark.read.json and call saveAsTable, since createDataFrame does not accept Python lists
  4. DRun spark.sql with an INSERT INTO catalog.schema.chunks_bronze VALUES statement built by string interpolation from the list of chunk dicts
  5. EConvert the list of dicts to a pandas DataFrame and write it with to_csv('catalog.schema.chunks_bronze'), then confirm the table in Catalog Explorer
Show answer & explanation

Correct answer: A

WHY A is correct: The canonical PySpark pattern for writing Python-generated data to a Unity Catalog Delta table is: Python list → spark.createDataFrame() → Delta write via saveAsTable(). spark.createDataFrame(chunk_list) directly accepts a list of Python dicts (or list of Row objects) and can infer or be given an explicit schema. saveAsTable('catalog.schema.chunks_bronze') registers the table in Unity Catalog under the three-level namespace (catalog.schema.table), making it a managed Delta table with full governance. Providing an explicit StructType schema is best practice to avoid type inference errors — especially for the chunk_index and page_number integer fields that could otherwise be inferred as long or nullable. WHY NOT E: pandas_df.to_csv() writes a CSV _file_ to a filesystem path, not to a Unity Catalog table. You would be writing the path string 'catalog.schema.chunks_bronze' as a local filename, not as a Unity Catalog table reference. CSV files are not Delta tables and are not registered in Unity Catalog's metastore. This approach fails both the Delta format requirement and the Unity Catalog registration requirement. WHY NOT C: spark.createDataFrame() absolutely CAN accept Python lists directly — this is a fundamental PySpark API capability. The DBFS intermediate step is unnecessary and adds I/O overhead. The claim that spark.createDataFrame() requires a serialized file is false. WHY NOT D: Building an INSERT VALUES SQL statement via Python string interpolation is dangerous (SQL injection risk, escaping issues with quotes in text), not scalable (SQL string length limits), and not idiomatic Databricks. The correct way to load a Python list is via spark.createDataFrame(), not string-constructed DML. For 5,000 multi-sentence chunks, the SQL string would be enormous and likely exceed Spark SQL statement size limits. WHY NOT B: Pandas UDFs are transformation functions applied to existing DataFrame columns — they are not a data loading mechanism. There is no standard pattern of 'apply a UDF to an empty DataFrame to generate data.' This answer describes a convoluted workaround that is not a documented pattern and would not work as described.

Take the full GenAI Engineer practice test →