This story begins with a book and ends with a book. It starts in an attic and ends in another attic, that of the Yorkshire cottage where I now sit writing.
It opens in the attic of my grandparents' house in Jerusalem in the spring of 1987 and, eighteen years later, closes with the appearance of my first novel, The Genizah at the House of Shepher.

Genizah (the Hebrew word, meaning literally "hiding place," refers to a depository for old or damaged sacred documents) is the saga of a Jerusalem family stretching over a hundred and forty-five years and four generations, but it is also a thriller about a missing biblical codex and the search for the true text of the Bible. The tale of the family Shepher, their aspirations, feuds and love affairs, is very much fiction, but the real-life history which inspired me to write it is just as full of mystery, intrigue and scholarly adventure, if not quite in the Indiana Jones mould, then perhaps as close as biblical studies ever get to that.

It concerns a series of events which led to the reconstruction of one of the most important biblical texts, the Keter Aram Soba or Aleppo Codex. Written in Tiberias in the tenth century, this is the copy believed to have been consulted by Maimonides when compiling the laws pertaining to Torah scrolls in his Mishneh Torah. The Codex was extensively damaged in 1947 when Aleppo's Jewish community was attacked and its synagogue burned down. It is believed that members of the community attempted to save the book by hiding a few pages each. While some have been retrieved, about two hundred are still missing, including all five books of the Torah.

What is the link between the Aleppo Codex and the family Yellin? Around 1854 my great-great-grandfather, Shalom Shachne Yellin, left his hometown of Skidel in Lithuania to make the long journey to Jerusalem. A famous scroll-checker in his native country, he was asked by the rabbis of every community along the way to inspect their Torah scrolls, and it was two years before he finally reached his destination. When he arrived in Jerusalem, he was asked by the religious authorities there to embark on yet another journey: to Aleppo in Syria, to examine the famous Keter Aram Soba, regarded by many as the most perfect text of the Bible in existence. The Codex was kept hidden by the Aleppo community, who refused access even to the most respected of biblical scholars, but armed with a letter of recommendation signed by all the great rabbis of Jerusalem, Shalom Shachne was to study the text and compare it to that currently in use, noting down all the necessary corrections.

By this time my great-great-grandfather was seventy years of age and in failing health, so he appointed his son-in-law, Yehoshua Kimchi, to be his substitute. Kimchi was less adept, but by writing down all the necessary questions and instructions Shalom Shachne provided him with the tools required to complete the job. Some ten years after the rabbis' first request, Kimchi set off for Aleppo. On his return, the book in which he had written his vital notes was kept at the house of Shalom Shachne's son, Zvi Hirsch the Scribe, and for years the scribes and scholars of Jerusalem, seeking to solve problems or answer questions about the text and punctuation of the Bible, would visit to consult it.

Then, on the death of Zvi Hirsch around 1915, the book disappeared. My grandfather, Yitzhak Yaacov, under threat of conscription into the Turkish army, had gone into hiding, first in Jerusalem and later in Petah Tikvah. By the time he returned, his father's books and papers had been put away. In the struggle to rebuild his life and earn a living – my father was one of eleven children – he never found time to investigate their contents, and in any case, was probably more interested in other things. As one of the first Hebrew journalists in the holy city he read widely and wrote copiously under numerous pseudonyms, covering politics, literature and religion, and at one time edited and published a weekly newspaper, Hed Ha'Am. He also worked as a teacher and compiled some of the early modern Hebrew grammars.

When in the 1920s my grandfather built his bungalow in the new district of Kiriat Moshe, he transferred the mass of documents into the attic, where it was gradually joined, over the next six decades, by a burgeoning archive of newspapers, diaries and family letters. After the destruction of the Aleppo synagogue a number of scholars and rabbis urged the family to try and find the book, but it never occurred to anyone that it was lying there, hidden in an old tin box, a few metres above their heads.

In April 1987 I was recalled to Jerusalem by the news that the house was scheduled for imminent demolition and that if I wanted to see it one last time I must come quickly. It was a sad visit: the bungalow with its stone floors and red tiled roof, scene of so many family reunions, our home-from-home on so many long hot summer visits throughout my childhood, stood forlorn, its contents piled in dusty heaps. But it was also to be the scene of a revelation. Guided by my uncle up the rickety ladder to the attic, I was confronted by an unforgettable image: a haphazard family archive so vast that the very dust on the floorboards was composed of disintegrating paper.

Here were complete sets of all my grandfather's newspapers dating back to 1910; diaries describing his experiences in hiding during the First World War; files of correspondence including letters between Shalom Shachne and his family back in Skidel, some written in code, full of anecdotes about the Jerusalem and Lithuanian communities. And, of course, the book. Seated amidst this treasure, running my hands through the soft dust of what had been already lost, the seed of the novel I would eventually write was planted.

When my uncle came across the old book in the attic he didn't know what it was. He actually picked it up and set it down again, leaving it there along with other sacred documents for eventual transfer to a genizah. Fortunately, my cousin had a friend at the Gush Etzion Yeshivah, whom she invited to examine what was left. On his return to the yeshivah he mentioned to friends that he had seen books belonging to Shalom Shachne Yellin. One of those friends was Yosef Ofer, who had assisted Amnon Shamosh in the writing of a recent book about the Aleppo Codex. He realised immediately what the book must be, and was overjoyed. He arranged for the retrieval of the precious volume.

The family heard on the television news that the book which had been sought for so many years had finally been found. My uncle told Ofer: "We gave you a suit, but did not know that it had a treasure in its pocket." And Ofer returned the book.

The family decided to donate the book to the Ben Zvi Institute in Jerusalem, but even now the saga was not quite over. Challenged by distant relatives, a legal contest ensued as the final act in this circuitous history. They eventually lost the case. The book was handed over to the scholars, and was instrumental in the landmark reconstruction of the Aleppo text, published in 2001 as Keter Yerushalayim.

The result of my own labours, meanwhile, took slightly longer to appear. Proficient but not fluent in Hebrew, with limited access to sources and a somewhat open-ended notion of what it was I wanted to achieve, my researches took place haphazardly over years and continents. The writing of the novel itself became a rite of passage, the search for a final text mirroring painfully, sometimes, the theme of textual perfection in the Torah that I was exploring. My story was not only to be an academic thriller, but an interrogation of Jewish identity, a meditation on exile and belonging, and, along the way, a love story. In constructing what I call the "mythical history" of the family Shepher, I was re-imagining and striving to come to terms with my own family narrative and with my place in it.

Now the work is done and the book lies before me, at once solid and oddly unreal, a simultaneous source of naches, satisfaction, and frustration in that it could never encompass all I wanted to achieve. But then I remember the rabbinical dictum: "It is not your duty to complete the work, but neither are you free to desist from it." And I put it aside, and turn to another book.

This essay first appeared in The Jewish Quarterly.