Keyword Search

Chroma uses SQLite for storing metadata and documents. Additionally documents are indexed using SQLite FTS5 for fast text search.

  1. import chromadb
  2. from chromadb.config import Settings
  3. client = chromadb.PersistentClient(path="test", settings=Settings(allow_reset=True))
  4. client.reset()
  5. col = client.get_or_create_collection("test")
  6. col.upsert(ids=["1", "2", "3"], documents=["He is a technology freak and he loves AI topics", "AI technology are advancing at a fast pace", "Innovation in LLMs is a hot topic"],metadatas=[{"author": "John Doe"}, {"author": "Jane Doe"}, {"author": "John Doe"}])
  7. col.query(query_texts=["technology"], where_document={"$or":[{"$contains":"technology"}, {"$contains":"freak"}]})

The above should return:

  1. {'ids': [['2', '1']],
  2. 'distances': [[1.052205477809135, 1.3074231535113972]],
  3. 'metadatas': [[{'author': 'Jane Doe'}, {'author': 'John Doe'}]],
  4. 'embeddings': None,
  5. 'documents': [['AI technology are advancing at a fast pace',
  6. 'He is a technology freak and he loves AI topics']],
  7. 'uris': None,
  8. 'data': None}

November 29, 2023