Async python with asyncio

You have two options for concurrent python Traditionally, we used threads with python for concurrency, but the release of the asyncio library (version 3.4) and the release of async/await syntax (version 3.5) created support for native coroutines that are familiar to users of the many languages that support it. (history of asyncio) asyncio (docs) The…

tiktoken: get number of tokens from string + openai pricing

Get the number of tokens The encoding cl100k_base is used by gpt-4, gpt-3.5-turbo, text-embedding-ada-002.This is how you encode a string into the tokens. You can abstract this into a separate function. Source: openai-cookbook (github) OpenAI Pricing As of November 22, 2023 Splitting chunks for to manage Context Window Limits gpt-3.5-turbo-1106 has a limit of 16,385…

Django and pgvector for semantic search

Goal: Semantic Search Setup pgvector You have a model with a field you want to make semantically searchable. Installation comes from: https://github.com/pgvector/pgvector-python Step: install pgvector on your machine Step: create a migration to activate Step: add a VectorField to your model Step: make migrations and migrate Setup sentence transformers for embeddings We will use the…