Building your first application

Let’s create an application with a local Chroma database, the OpenAI LLM gpt-3.5-turbo, and the OpenAI embedding model text-embedding-ada-002.

Since we are using OpenAI components, we first have to set the OpenAI API key as described here. For example, in bash run

export OPENAI_API_KEY=[your token]

Next, create a config file config.yaml in the root of your project with the following content:

database:
  provider: "chroma"
  number_search_results: 5
  base_dir: "data/database"

splitter:
  chunk_overlap: 256
  chunk_size: 1024

embedding:
  provider: "openai"
  model: "text-embedding-ada-002"

llm:
  provider: "openai"
  model: "gpt-3.5-turbo"

You can find more details and configuration options in the section Configuration.

Next, create a Python file for the application code. Your project should look similar to this example now:

myapp/
├── app.py
├── config.yaml

Finally, in the app.py file, we can implement our application using the components specified in the configuration. The following demonstrates the main methods:

from ragcore import RAGCore

USER = "01" # Optionally use a string to identify a user

app = RAGCore() # pass config=<path-to-config.yaml> if not in root

# Upload a document "My_Book.pdf"
app.add(path="My_Book.pdf", user=USER)

# Now you can ask questions
answer = app.query(query="What did the elk say?", user=USER)

print(answer.content)

# List the document's title and content on which the answer is based
for doc in answer.documents:
  print(doc.title, " | ", doc.content)

# Get the user identifier
print(answer.user)

# List all documents in the database
print(rag_instance.get_titles(user=USER))

# You can delete by title
app.delete(title="My_Book", user=USER)

If your app should support more than one user with separate data for each, you can pass in a string user to identify a user.

And that’s it! For more details on configuration options, please refer to the Configuration section.