Thursday, 10 July 2025

Docker Compose will auto load .env variable

 Docker Compose retrieves environment variables from a .env file located in the same directory as your docker-compose.yml file. This is the default and most common method.

How it works:

Placement:

Create a file named .env in the root directory of your Docker Compose project, alongside your docker-compose.yml file.

Content:

Define your environment variables within this .env file using a simple key-value pair format, one variable per line:

Code


    VARIABLE_NAME=variable_value

    ANOTHER_VAR=another_value

Referencing in docker-compose.yml: In your docker-compose.yml file, you can then reference these variables using the ${VARIABLE_NAME} syntax for interpolation:

Code


    version: '3.8'

    services:

      web:

        image: "my-app:${APP_VERSION}"

        environment:

          - DB_HOST=${DATABASE_HOST}

Automatic Loading: When you run docker compose up (or docker-compose up with older versions), Docker Compose automatically detects and loads the variables from the .env file, substituting them into your docker-compose.yml configuration before creating and starting the services.

Wednesday, 9 July 2025

iFrame remove scroll bar

 https://stackoverflow.com/questions/10082155/remove-scrollbar-from-iframe



dd scrolling="no" attribute to the iframe.


<iframe src="http://buythecity.com"  scrolling="no" ...>

Ubuntu set folder permission for inheritance (setfacl)

 https://serverfault.com/questions/444867/linux-setfacl-set-all-current-future-files-directories-in-parent-directory-to


sudo setfacl -Rdm g:groupnamehere:rwx /base/path/members/
sudo setfacl -Rm g:groupnamehere:rwx /base/path/members/

R is recursive, which means everything under that directory will have the rule applied to it.
d is default, which means for all future items created under that directory, have these rules apply by default. m is needed to add/modify rules.

The first command, is for new items (hence the d), the second command, is for old/existing items under the folder. Hope this helps someone out as this stuff is a bit complicated and not very intuitive.


U can add others:


sudo setfacl -d -m g:your_group:rwx,o:rx /path/to/parentsudo setfacl -d -m g:your_group:rw,o:r /path/to/parent

Friday, 4 July 2025

ES search with embedding

 

How “Search by Embedding” Works

1. Index Phase

  1. Choose an embedding model, for example text-embedding-3-small.

  2. For each new question, compute its embedding and store both text and vector in Elasticsearch:

    go
    emb := EmbedText("How do I apply for a mortgage in Canada?") // emb is []float32, e.g. [0.20, 0.80, -0.10, …] // Then index into ES: PUT /qa_memory/_doc/<uuid> { "text": "How do I apply for a mortgage in Canada?", "embedding": [0.20, 0.80, -0.10, …] }

2. Query Phase

  1. Embed the incoming question the same way:

    go
    qEmb := EmbedText("What's the process to get a home loan in Canada?") // qEmb might be [0.19, 0.79, -0.05, …]
  2. Ask Elasticsearch for the most similar vector using cosine similarity:

    json
    GET /qa_memory/_search { "size": 1, "query": { "script_score": { "query": { "match_all": {} }, "script": { "source": "cosineSimilarity(params.vec, 'embedding') + 1.0", "params": { "vec": qEmb } } } } }

    Why + 1.0?
    Cosine similarity ranges from –1 to +1; adding 1.0 shifts it to [0, 2], keeping all scores positive.

3. Example (3-Dimensional)

IDTextEmbedding
doc1“Apply for a mortgage in Canada?”[0.20, 0.80, –0.10]
doc2“Best restaurants in Vancouver”[–0.50, 0.10, 0.70]
  • New query embedding: [0.19, 0.79, –0.05]

  • Cosine similarity with doc1 ≈ 0.99 → very high → reuse doc1

  • Similarity with doc2 is much lower → ignore doc2

4. Decision Threshold

  • If top score > 1.8 (i.e. cosine + 1.0)
    → consider it “already answered” and reuse that stored Q&A.

  • Otherwise, send the question to GPT, then embed & index its answer for future reuse.



1.8 (shifted) – 1.0 = 0.8 (raw cosine)
80%