Quick Start Guide
Get document search up and running with a few lines of code. Chunk, embed, store, vector search, and rerank, all in a single location.
Video Quickstart
You’ll need to generate an API key and a create Space where files are uploaded.
Generate API Key
- Log in to Tada AI app.tadatoday.ai
- Click the gear icon in the bottom left corner. Click
Settings / API Key
. - In the sidebar, click
Personal API Keys
- Press
New API Key
and select how long you want it to be active for
The API key will only be shown once, so make sure to save it somewhere secure.
Install the python client
Install our client library. It’s an easy to use wrapper around our rest endpoints.
pip install tada_ai
Upload a file
A space is how files are stored and organized. There similar to a Google Drive or an S3 Bucket. You can have as many spaces as you want, and you can scope searches to specific spaces.
from tada_ai import TadaAIClientimport mimetypesimport os
api_key = ''#your api_key here.client = TadaAIClient(api_key=api_key)space = client.spaces.create("My Space")print(f"Space created: {space}")
# Single location for the full file pathfile_path = r""# your file path herefile_name = os.path.basename(file_path) # Extract the file name from the file path
with open(file_path, 'rb') as file: # Make sure to open binary files with 'rb' space_file = client.space_files.create( space.id, file, path=file_name, # Using the file name as the path (name) within the space mime_type=mimetypes.guess_type(file_path)[0], # Extract the mime type )print(f"SpaceFile created: {space_file}")print(f"Status: {space_file.status}")
API Key Environment Variable
You can also define the API key in the envrionment variable TADA_AI_API_KEY
. Creating a client without passing in an api_key
will default to this variable. If no key is present, the client will throw an error.
Checking the file status
Files have 4 statuses:
Pending
: The file was received and is waiting to be processedProcessing
: The file is queued for processingReady
: The file is indexed and is ready to be searchedError
: An error occurred while processing the file
Currently, we only support polling the API endpoints for file status changes.
space_file = client.space_files.get(space_file.id)print(f"Space file: {space_file}")print(f"Status: {space_file.status}")
Perform a search
from tada_ai import ChunkOptions, RerankerOptions
prompt = "Your query here"search_result = client.search( prompt, space_id=space.id, chunks=ChunkOptions( # Default settings. Can leave this out entirely requested_min_word_count=50, requested_max_word_count=1500 ), reranker=RerankerOptions( # Default settings. Can leave this out entirely top_n=10, # max number of results - Can be set between 1 and 20 threshold=0.25 # between 0 and 1 ),)#Note: How does word count work? The API uses content blocks and chunks to identify word count minimums and maximums. This means that the specified min and max word counts may be rounded up.#For example, if you request a min word count of 3 and ask about the sentence "how does word count work," (i.e. the above paragraph) the entire paragraph will be returned, resulting in a word count of 33 instead of 3. We do this to ensure your answer isn't cut off.
print(f"Results:\n")
for chunk in search_result.chunks: print(f"---------- CHUNK. Score: {chunk.score}") print(chunk.markdown) print("\n\n")
Example Results
Results:
---------- CHUNK. Score: 0.9Markdown content for chunk 1...
---------- CHUNK. Score: 0.85Markdown content for chunk 2...
...
Generating an AI answer
You can feed our search results directly into an LLM. We provide chunk content in markdown. LLMs are really good at inderstanding the relationship between headers, lists and paragraphs, and generating answers from content.
pip install groq
GROQ_API_KEY = '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'
from groq import Groq
client = Groq( api_key=GROQ_API_KEY,)
document_string = '\n\n'.join(chunk.markdown for chunk in search_result.chunks)document_chunks = f"""QUESTION: {prompt}DOCUMENTATION:{document_string}"""
chat_completion = client.chat.completions.create( messages=[ { "role": "user", "content": f''' You are an expert research assistant. Here is a document you will answer questions about: First, find the quotes from the document that are most relevant to answering the question, and then print them in numbered order. Quotes should be relatively short. {document_chunks} If there are no relevant quotes, write only "N/A" Then, answer the question, starting with "Answer:". Do not include or reference quoted content verbatim in the answer. Don't say "According to Quote [1]" when answering. Instead make references to quotes relevant to each section of the answer solely by adding their bracketed numbers at the end of relevant sentences. Thus, the format of your overall response should look like what's shown between the <example></example> tags. Make sure to follow the formatting and spacing exactly. <example> Quotes: [1] "Company X reported revenue of $12 million in 2021." [2] "Almost 90% of revene came from widget sales, with gadget sales making up the remaining 10%."
Answer: Company X earned $12 million. [1] Almost 90% of it was from widget sales. [2]
</example> Question: {prompt}''', } ], model="llama3-8b-8192",)
print(chat_completion.choices[0].message.content)